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

ragged array setitem bug fix: setitem with null slice operation #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions enspara/ra/ra.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,12 @@ def __setitem__(self, iis, value):
value = value._array
# ints, slices, lists, and numpy objects are handled by numpy
if isinstance(iis, (numbers.Integral, slice, list, np.ndarray)):
self._array[iis] = value
self.__init__(self._array)
if iis == slice(None, None, None):
self._data[iis] = value
self.__init__(self._data, lengths=self.lengths)
else:
self._array[iis] = value
self.__init__(self._array)
# tuples get index conversion from 2d to 1d
elif isinstance(iis, tuple):
first_dimension, second_dimension = iis
Expand Down
8 changes: 7 additions & 1 deletion enspara/test/test_ra.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ def test_ra_operator_not_implemented(self):
with assert_raises(TypeError):
a > 'asdfasdfasd'

def test_ra_null_slice(self):
a = ra.RaggedArray(np.arange(15), lengths=[2,3,15])
a[:] = 22
assert np.all(a._data == np.ones(15, dtype=int)*22)



class TestParallelLoad(unittest.TestCase):

Expand Down Expand Up @@ -663,7 +669,7 @@ def test_concat_atoms(self):
trjlist = [md.load(self.top_fname)] * 10
trj = concatenate_trjs(trjlist, atoms=ATOMS)

assert_equals(len(trjlist), len(trj))
assertEqual(len(trjlist), len(trj))

for trjframe, trjlist_item in zip(trj, trjlist):
sliced_item = trjlist_item.atom_slice(
Expand Down