Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Setting the formula of a base cells not affecting its sub(#141) #142

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions modelx/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,8 +1437,9 @@ def change_cells_formula(self, cells, func):
define = True
for space in self._get_subs(cells.parent, skip_self=False):
c = space.cells[cells.name]
if c is not cells and c.is_defined():
break # Stop when sub cells is defined
if (c is not cells and c.is_defined() and
self.get_deriv_bases(c, defined_only=True)[0] is cells):
continue # Skip when c's base is not cells
space.clear_subs_rootitems()
space.cells[cells.name].on_change_formula(func, define)
define = False # Do not define derived cells
Expand Down
27 changes: 26 additions & 1 deletion modelx/tests/core/cells/test_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,29 @@ def test_set_formula_with_defined_sub(sample_for_rename_and_formula):

assert not len(foo)
# assert len(sub1.Child1.Foo) # Not Cleared
# assert sub1.Child1.Foo(1) == 3 # Not Changed
# assert sub1.Child1.Foo(1) == 3 # Not Changed


def test_set_base_formula_with_defined_sub():
"""Setting the formula of a base cells not affecting its sub

https://github.com/fumitoh/modelx/issues/141

Base----foo
+----Sub1---foo(defined)
+----Sub2---foo(derived)
"""
m = mx.new_model()
base = m.new_space('Base')
sub1 = m.new_space('Sub1', bases=base)
sub2 = m.new_space('Sub2', bases=base)

sub1.new_cells('foo')
base.new_cells('foo')
assert 'foo' in sub2

@mx.defcells(space=base)
def foo():
return "base"

assert sub2.foo() == "base"
Loading