Skip to content

Commit

Permalink
ENH: df.iloc accepts zero dim integer np.array as int
Browse files Browse the repository at this point in the history
  • Loading branch information
tamuhey committed Jan 25, 2019
1 parent 539c54f commit cb98d2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2222,7 +2222,12 @@ def _getitem_axis(self, key, axis=None):

# a single integer
else:
if not is_integer(key):
# zero_dim integer np.array is converted to int
if isinstance(key, np.ndarray) and key.ndim == 0 \
and issubclass(key.dtype.type, np.integer):
key = key.item()

elif not is_integer(key):
raise TypeError("Cannot index by location index with a "
"non-integer key")

Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/indexing/test_iloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,3 +675,10 @@ def test_identity_slice_returns_new_object(self):
# should also be a shallow copy
original_series[:3] = [7, 8, 9]
assert all(sliced_series[:3] == [7, 8, 9])

def test_indexing_zero_dim_np_array(self):
# GH24919
df = DataFrame([[1, 2], [3, 4]])

# should not raise an error
df.iloc[np.array(0)]

0 comments on commit cb98d2a

Please sign in to comment.