Skip to content

Commit 5fc0120

Browse files
committed
ENH: df.loc accepts zerodim integer np.array, and add test
1 parent 16bbaa9 commit 5fc0120

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: pandas/core/indexing.py

+1
Original file line numberDiff line numberDiff line change
@@ -1857,6 +1857,7 @@ def _getitem_axis(self, key, axis=None):
18571857
if axis is None:
18581858
axis = self.axis or 0
18591859

1860+
key = item_from_zerodim(key)
18601861
if is_iterator(key):
18611862
key = list(key)
18621863

Diff for: pandas/tests/indexing/test_loc.py

+11
Original file line numberDiff line numberDiff line change
@@ -765,3 +765,14 @@ def test_loc_setitem_empty_append_raises(self):
765765
msg = "cannot copy sequence with size 2 to array axis with dimension 0"
766766
with pytest.raises(ValueError, match=msg):
767767
df.loc[0:2, 'x'] = data
768+
769+
def test_indexing_zero_dim_np_array(self):
770+
# GH24924
771+
df = DataFrame([[1, 2], [3, 4]])
772+
773+
# should not raise an error
774+
result = df.loc[np.array(0)]
775+
776+
# expected series
777+
sr = pd.Series([1, 2], name=0)
778+
tm.assert_series_equal(result, sr)

0 commit comments

Comments
 (0)