Skip to content

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

Merged
merged 8 commits into from
Nov 12, 2019

Conversation

jbrockmendel
Copy link
Member

cc @WillAyd @jreback orthogonal to other groupby PRs (including #29499) but will have merge conflicts. No preference on what order they should go in.

@gfyoung gfyoung added Error Reporting Incorrect or improved errors from pandas Internals Related to non-user accessible pandas implementation labels Nov 9, 2019
Copy link
Member

@simonjayhawkins simonjayhawkins left a 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
Copy link
Member

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

Copy link
Member Author

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`"):
Copy link
Member

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?

Copy link
Member Author

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.

@jreback jreback added this to the 1.0 milestone Nov 12, 2019
@jreback
Copy link
Contributor

jreback commented Nov 12, 2019

lgtm. can you merge master here and merge on green.

@jbrockmendel
Copy link
Member Author

rebased+green; ping.

@jreback jreback merged commit ab9dca0 into pandas-dev:master Nov 12, 2019
@jreback
Copy link
Contributor

jreback commented Nov 12, 2019

thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the faster-ngroups3 branch November 12, 2019 23:18
Reksbril pushed a commit to Reksbril/pandas that referenced this pull request Nov 18, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants