Skip to content

Commit df1fbd4

Browse files
committed
fix some issues with make_dirty
on test: - make_dirty([[1,2,3]], dirty={(0,0):0, (0,1):0}) with cellzero=0 the expected result is [[3]] (but was [[2]] because it starts removing 1 in [1,2,3], then 3 in [2,3], instead of removing 1 and 2 in [1,2,3] - same test with non zero cell basically, this doesn't assume the key traversal is ordered in dirty additionaly, it use a default cellzero value (to `None`)
1 parent 4d241ae commit df1fbd4

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Diff for: sage_widget_adapters/generic_grid_view_adapter.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,25 @@ def make_dirty(self, l, dirty={}):
207207
[[1, 2, 5, 6], [3, 7, 42], [4]]
208208
sage: ga.make_dirty(t.to_list(), {(2,0):0})
209209
[[1, 2, 5, 6], [3, 7]]
210+
sage: ga.make_dirty(t.to_list(), {(0,2):0, (0,3):0})
211+
[[1, 2], [3, 7], [4]]
210212
"""
213+
cellzero = None
214+
if hasattr(self, 'cellzero'):
215+
cellzero = self.cellzero
211216
for p in dirty:
212217
if p[0] < len(l):
213218
if p[1] < len(l[p[0]]):
214-
if dirty[p] == self.cellzero:
215-
del l[p[0]][p[1]]
216-
else:
217-
l[p[0]][p[1]] = dirty[p]
218-
elif len(l[p[0]]) == p[1] and dirty[p] != self.cellzero:
219+
l[p[0]][p[1]] = dirty[p]
220+
elif len(l[p[0]]) <= p[1] and dirty[p] != cellzero:
221+
# padding with cellzero
222+
l[p[0]] += [cellzero] * (p[1] - len(l[p[0]]))
219223
l[p[0]].append(dirty[p])
220224
else:
221225
for i in range(p[0] - len(l)):
222226
l.append([])
223-
l.append([dirty[p]])
227+
l.append([cellzero] * p[1] + [dirty[p]])
228+
l = [[ val for val in row if val != cellzero ] for row in l]
224229
return [val for val in l if val]
225230

226231
def set_cell(self, obj, pos, val, dirty={}, constructorname=''):

0 commit comments

Comments
 (0)