Skip to content
Permalink
Browse files

ENH: df.iloc accepts zero dim integer np.array as int

  • Loading branch information...
tamuhey committed Jan 25, 2019
1 parent 539c54f commit cb98d2ad5e0614edc812f7405270ccbb11312afb
Showing with 13 additions and 1 deletion.
  1. +6 −1 pandas/core/indexing.py
  2. +7 −0 pandas/tests/indexing/test_iloc.py
@@ -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")

@@ -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.
You can’t perform that action at this time.