From 9bd6491759f4ea5733a0fb175df67720206dac4b Mon Sep 17 00:00:00 2001 From: Yohei Tamura Date: Sun, 27 Jan 2019 14:28:04 +0900 Subject: [PATCH] ENH: df.__getitem__ accepts zerodim integer np.array, and add test --- pandas/core/frame.py | 1 + pandas/tests/frame/test_indexing.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index b4f79bda25517..fe2ca72b46977 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2881,6 +2881,7 @@ def _ixs(self, i, axis=0): return result def __getitem__(self, key): + key = lib.item_from_zerodim(key) key = com.apply_if_callable(key, self) # shortcut if the key is in columns diff --git a/pandas/tests/frame/test_indexing.py b/pandas/tests/frame/test_indexing.py index 19b8ae4eb6e0f..d36af9b89fe58 100644 --- a/pandas/tests/frame/test_indexing.py +++ b/pandas/tests/frame/test_indexing.py @@ -3682,3 +3682,14 @@ def test_functions_no_warnings(self): with tm.assert_produces_warning(False): df['group'] = pd.cut(df.value, range(0, 105, 10), right=False, labels=labels) + + def test_getitem_zerodim_np_array(self): + # GH24924 + df = DataFrame([[1, 2], [3, 4]]) + + # should not raise an error + result = df[np.array(0)] + + # expected series + sr = pd.Series([1, 3], name=0) + tm.assert_series_equal(result, sr)