Skip to content
Permalink
Browse files

ENH: df.__getitem__ accepts zerodim integer np.array, and add test

  • Loading branch information...
tamuhey committed Jan 27, 2019
1 parent 5fc0120 commit 9bd6491759f4ea5733a0fb175df67720206dac4b
Showing with 12 additions and 0 deletions.
  1. +1 −0 pandas/core/frame.py
  2. +11 −0 pandas/tests/frame/test_indexing.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
@@ -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)

0 comments on commit 9bd6491

Please sign in to comment.
You can’t perform that action at this time.