Skip to content

Commit

Permalink
TST: follow-up ot pandas-dev#30318 (pandas-dev#30326)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and AlexKirko committed Dec 29, 2019
1 parent ca22a19 commit 9f95069
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 1 addition & 4 deletions pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,7 @@ def _aggregate_series_pure_python(self, obj: Series, func):
if len(res) == 1:
# e.g. test_agg_lambda_with_timezone lambda e: e.head(1)
# FIXME: are we potentially losing import res.index info?

# TODO: use `.item()` if/when we un-deprecate it.
# For non-Series we could just do `res[0]`
res = next(iter(res))
res = res.item()
else:
raise ValueError("Function does not reduce")
result = np.empty(ngroups, dtype="O")
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/extension/base/getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,10 @@ def test_item(self, data):
s = pd.Series(data)
result = s[:1].item()
assert result == data[0]

msg = "can only convert an array of size 1 to a Python scalar"
with pytest.raises(ValueError, match=msg):
s[:0].item()

with pytest.raises(ValueError, match=msg):
s.item()

0 comments on commit 9f95069

Please sign in to comment.