Skip to content

Commit 9bd6491

Browse files
committed
ENH: df.__getitem__ accepts zerodim integer np.array, and add test
1 parent 5fc0120 commit 9bd6491

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: pandas/core/frame.py

+1
Original file line numberDiff line numberDiff line change
@@ -2881,6 +2881,7 @@ def _ixs(self, i, axis=0):
28812881
return result
28822882

28832883
def __getitem__(self, key):
2884+
key = lib.item_from_zerodim(key)
28842885
key = com.apply_if_callable(key, self)
28852886

28862887
# shortcut if the key is in columns

Diff for: pandas/tests/frame/test_indexing.py

+11
Original file line numberDiff line numberDiff line change
@@ -3682,3 +3682,14 @@ def test_functions_no_warnings(self):
36823682
with tm.assert_produces_warning(False):
36833683
df['group'] = pd.cut(df.value, range(0, 105, 10), right=False,
36843684
labels=labels)
3685+
3686+
def test_getitem_zerodim_np_array(self):
3687+
# GH24924
3688+
df = DataFrame([[1, 2], [3, 4]])
3689+
3690+
# should not raise an error
3691+
result = df[np.array(0)]
3692+
3693+
# expected series
3694+
sr = pd.Series([1, 3], name=0)
3695+
tm.assert_series_equal(result, sr)

0 commit comments

Comments
 (0)