Skip to content

Commit e38be24

Browse files
committed
ENH: df.iloc accepts zero dim integer np.array as int
1 parent 539c54f commit e38be24

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pandas/core/indexing.py

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66

77
from pandas._libs.indexing import _NDFrameIndexerBase
8+
from pandas._libs.lib import item_from_zerodim
89
import pandas.compat as compat
910
from pandas.compat import range, zip
1011
from pandas.errors import AbstractMethodError
@@ -2222,6 +2223,7 @@ def _getitem_axis(self, key, axis=None):
22222223

22232224
# a single integer
22242225
else:
2226+
key = item_from_zerodim(key)
22252227
if not is_integer(key):
22262228
raise TypeError("Cannot index by location index with a "
22272229
"non-integer key")

pandas/tests/indexing/test_iloc.py

+7
Original file line numberDiff line numberDiff line change
@@ -675,3 +675,10 @@ def test_identity_slice_returns_new_object(self):
675675
# should also be a shallow copy
676676
original_series[:3] = [7, 8, 9]
677677
assert all(sliced_series[:3] == [7, 8, 9])
678+
679+
def test_indexing_zero_dim_np_array(self):
680+
# GH24919
681+
df = DataFrame([[1, 2], [3, 4]])
682+
683+
# should not raise an error
684+
df.iloc[np.array(0)]

0 commit comments

Comments
 (0)