Skip to content

Commit dcd5733

Browse files
jbrockmendelproost
authored andcommitted
1 parent 5ffd18a commit dcd5733

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

pandas/core/groupby/ops.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -663,10 +663,7 @@ def _aggregate_series_pure_python(self, obj: Series, func):
663663
if len(res) == 1:
664664
# e.g. test_agg_lambda_with_timezone lambda e: e.head(1)
665665
# FIXME: are we potentially losing import res.index info?
666-
667-
# TODO: use `.item()` if/when we un-deprecate it.
668-
# For non-Series we could just do `res[0]`
669-
res = next(iter(res))
666+
res = res.item()
670667
else:
671668
raise ValueError("Function does not reduce")
672669
result = np.empty(ngroups, dtype="O")

pandas/tests/extension/base/getitem.py

+7
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,10 @@ def test_item(self, data):
272272
s = pd.Series(data)
273273
result = s[:1].item()
274274
assert result == data[0]
275+
276+
msg = "can only convert an array of size 1 to a Python scalar"
277+
with pytest.raises(ValueError, match=msg):
278+
s[:0].item()
279+
280+
with pytest.raises(ValueError, match=msg):
281+
s.item()

0 commit comments

Comments
 (0)