Skip to content

Commit

Permalink
Fix forgotten compatibility issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarnoud committed Jul 3, 2018
1 parent f3c0e7f commit 886ca15
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
23 changes: 10 additions & 13 deletions package/MDAnalysis/coordinates/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,12 @@ def __init__(self, trajectory):
def __len__(self):
raise NotImplementedError()

@staticmethod
def _avoid_bool_list(frames):
if isinstance(frames, list) and frames and isinstance(frames[0], bool):
return np.array(frames, dtype=bool)
return frames

def write(self, name, writer):
raise NotImplementedError()

Expand Down Expand Up @@ -922,10 +928,10 @@ def __len__(self):
start, stop, step = self.start, self.stop, self.step
if (step > 0 and start < stop):
# We go from a lesser number to a larger one.
return int(1 + (stop - 1 - start) / step)
return int(1 + (stop - 1 - start) // step)
elif (step < 0 and start > stop):
# We count backward from a larger number to a lesser one.
return int(1 + (start - 1 - stop) / (-step))
return int(1 + (start - 1 - stop) // (-step))
else:
# The range is empty.
return 0
Expand Down Expand Up @@ -963,15 +969,7 @@ def __getitem__(self, frame):
else:
# Indexing with a lists of bools does not behave the same in all
# version of numpy.
try:
is_bool = isinstance(frame[0], bool)
except (IndexError, TypeError):
# Empty sequence (IndexError) ot not subscriptable type such as
# a slice (TypeError)
pass
else:
if is_bool:
frame = np.asarray(frame)
frame = self._avoid_bool_list(frame)
frames = np.array(list(range(self.start, self.stop, self.step)))[frame]
return FrameIteratorIndices(self.trajectory, frames)

Expand Down Expand Up @@ -1054,6 +1052,7 @@ def __getitem__(self, frame):
frame = self.frames[frame]
return self.trajectory._read_frame_with_aux(frame)
else:
frame = self._avoid_bool_list(frame)
frames = np.array(self.frames)[frame]
return FrameIteratorIndices(self.trajectory, frames)

Expand Down Expand Up @@ -1537,10 +1536,8 @@ def __getitem__(self, frame):
start, stop, step = self.check_slice_indices(
frame.start, frame.stop, frame.step)
if start == 0 and stop == len(self) and step == 1:
#return self.__iter__()
return FrameIteratorAll(self)
else:
#return self._sliced_iter(start, stop, step)
return FrameIteratorSliced(self, frame)
else:
raise TypeError("Trajectories must be an indexed using an integer,"
Expand Down
4 changes: 0 additions & 4 deletions testsuite/MDAnalysisTests/coordinates/test_reader_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,6 @@ def sl():
[True, True, False, False, True, True, False, True, False, True],
[True, True, True, True, True, True, True, True, True, True],
[False, False, False, False, False, False, False, False, False, False],
np.array([True, False, True, False, True, False, True, False, True, False]),
np.array([True, True, False, False, True, True, False, True, False, True]),
np.array([True] * 10),
np.array([False] * 10),
])
def test_getitem(self, slice_cls, sl, reader):
sl = slice_cls(sl)
Expand Down

0 comments on commit 886ca15

Please sign in to comment.