Skip to content

Commit

Permalink
ENH: df.__getitem__ accepts zerodim integer np.array, and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
tamuhey committed Jan 27, 2019
1 parent 5fc0120 commit 9bd6491
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/frame/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.