Skip to content

Commit

Permalink
fix slicing when integer is a numpy int64
Browse files Browse the repository at this point in the history
  • Loading branch information
adrn committed Apr 18, 2019
1 parent f90f808 commit ea95575
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gala/dynamics/orbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __getitem__(self, slice_):
vel = self.vel[slice_]

# if one time is sliced out, return a phasespaceposition
if isinstance(slice_[0], int):
if isinstance(slice_[0], int) or isinstance(slice_[0], np.int_):
return PhaseSpacePosition(pos=pos, vel=vel, frame=self.frame)

else:
Expand Down
5 changes: 5 additions & 0 deletions gala/dynamics/tests/test_orbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ def test_slice():
assert isinstance(new_o, PhaseSpacePosition)
assert new_o.shape == (8,)

# REGRESSION TEST: numpy int64 is not an int()
new_o = o[np.int64(3)]
assert isinstance(new_o, PhaseSpacePosition)
assert new_o.shape == (8,)

# 3d slice on 3d
o = Orbit(pos=x, vel=v, t=t)
new_o = o[:5,:4]
Expand Down

0 comments on commit ea95575

Please sign in to comment.