Skip to content

Commit 003813b

Browse files
committed
RangeSetND: fix padding info when slicing using __getitem__() (#429)
Padding info may be lost when in RangeSetND.__getitem__() because we only checked the padding of the elements in the first tuple. Use existing pads() method to get the maximum padding length of each dimension instead. Closes #429. Change-Id: Ic3df8dd887f2d4f728ec4a6b568681c148af31ff
1 parent ba6ac69 commit 003813b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/ClusterShell/RangeSet.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,7 @@ def __getitem__(self, index):
956956
for rgvec in self._veclist:
957957
iveclist += product(*rgvec)
958958
assert(len(iveclist) == len(self))
959-
rnd = RangeSetND(iveclist[index],
960-
pads=[rg.padding for rg in self._veclist[0]],
959+
rnd = RangeSetND(iveclist[index], pads=self.pads(),
961960
autostep=self.autostep)
962961
return rnd
963962

tests/RangeSetNDTest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ def test_getitem_slices(self):
432432
# steps
433433
self.assertEqual(str(rn1[0:12:2]), "0-3; 1\n10; 10,12\n")
434434
self.assertEqual(str(rn1[1:12:2]), "0-3; 2\n10; 11,13\n")
435+
# GitHub #429
436+
rn1 = RangeSetND([["110", "15-16"], ["107", "06"]])
437+
self.assertEqual(str(rn1[0:3:2]), "107; 06\n110; 15\n")
435438

436439
def test_contiguous(self):
437440
rn0 = RangeSetND()

0 commit comments

Comments
 (0)