-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REF: Pre-empt ValueError in _aggregate_series_fast #29500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jbrockmendel. a few comments otherwise lgtm.
@@ -583,7 +583,11 @@ def _transform( | |||
return result | |||
|
|||
def agg_series(self, obj: Series, func): | |||
if is_extension_array_dtype(obj.dtype) and obj.dtype.kind != "M": | |||
if len(obj) == 0: | |||
# SeriesGrouper would raise if we were to call _aggregate_series_fast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm should we not just fix _aggregate_series_fast
to not raise in that case then? Hoping to avoid special casing like this in any groupby functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hoping to avoid special casing like this in any groupby functions
Agreed on the goal. ATM this is the best way to make progress towards that goal. In particular, making this explicit here is much clearer than catching the ValueError with the particular message on L600.
should we not just fix _aggregate_series_fast to not raise in that case then?
#29499 does something along those lines.
dummy = obj[:0] | ||
labels = np.array([-1, -1, -1, 0, 0, 0, 1, 1, 1, 1], dtype=np.int64) | ||
|
||
with pytest.raises(ValueError, match="SeriesGrouper requires non-empty `series`"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this visible from an end user perspective?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should never be raised to the user, just seemed like the behavior change merited a test.
lgtm. can you merge master here and merge on green. |
rebased+green; ping. |
thanks @jbrockmendel |
cc @WillAyd @jreback orthogonal to other groupby PRs (including #29499) but will have merge conflicts. No preference on what order they should go in.