Skip to content

Commit 150f632

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`) remove cellzero default value
1 parent 4d241ae commit 150f632

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

sage_widget_adapters/generic_grid_view_adapter.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,22 @@ 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
"""
211213
for p in dirty:
212214
if p[0] < len(l):
213215
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:
216+
l[p[0]][p[1]] = dirty[p]
217+
elif len(l[p[0]]) <= p[1] and dirty[p] != self.cellzero:
218+
# padding with cellzero
219+
l[p[0]] += [self.cellzero] * (p[1] - len(l[p[0]]))
219220
l[p[0]].append(dirty[p])
220221
else:
221222
for i in range(p[0] - len(l)):
222223
l.append([])
223-
l.append([dirty[p]])
224+
l.append([cellzero] * p[1] + [dirty[p]])
225+
l = [[ val for val in row if val != self.cellzero ] for row in l]
224226
return [val for val in l if val]
225227

226228
def set_cell(self, obj, pos, val, dirty={}, constructorname=''):
@@ -235,6 +237,7 @@ def set_cell(self, obj, pos, val, dirty={}, constructorname=''):
235237
sage: from sage.combinat.tableau import Tableau
236238
sage: t = Tableau([[1, 2, 5, 6], [3, 7], [4]])
237239
sage: ga = GridViewAdapter()
240+
sage: ga.cellzero = None
238241
sage: ga.set_cell(t, (1,1), 8, constructorname='Tableau')
239242
[[1, 2, 5, 6], [3, 8], [4]]
240243
sage: from sage.matrix.constructor import Matrix, matrix

0 commit comments

Comments
 (0)