-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Raise error in certain unhandled _reduce cases. #8592
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
@@ -2067,9 +2067,16 @@ def _reduce(self, op, axis=0, skipna=True, numeric_only=None, | |||
""" | |||
delegate = self.values | |||
if isinstance(delegate, np.ndarray): | |||
if axis != 0 and axis != self._AXIS_IALIASES[0]: |
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.
you can just do: axis = self._get_axis_number(axis)
(which errors if the axis is not valid / exceeds dims)
Oh, I’d thought there was possibly interest in supporting axis 1 (single element reduction along a perpendicular axis) because the preexisting group by tests I modified had been attempting to sum a series on axis 1. I changed to make this a value error per your comment. |
pls rebase and add a doc-note in v0.15.1 enhancements (reffing this pr as it doesn't have a separate issue) |
Ok, rebased and added to whatsnew. |
@staple sorry, you will have to rebase again, I moved the whatsnew file to a subfolder |
@staple pls squash as well, otherwise looks ok |
Ok, rebased and squashed. |
minor comment: is this error message only supposed to be raised internally? Or will users also see this in some cases? |
@jorisvandenbossche Users can see this error message. What would make more sense for a user message? Would something like 'Series aggregation does not implement numeric_only' make sense? |
Would it be possible to detect in which kind of aggregation function this is called? |
It looks like 'name' (the name of the aggregation function) is generally passed to _reduce. But it's an optional argument. I could try to make it a non optional argument, and use the value there in the error message. Would that make sense? |
I just wanted to suggest the same! |
Ok, cool. |
It is indeed an optional argument, bug eg in https://github.com/staple/pandas/blob/reduce/pandas/core/generic.py#L3924 where it is used in |
Ok, I made the requested changes. Left them in separate commits for now, for ease of review. But if you like I can squash them when you're ready. Let me know if the change to make 'name' a required argument to _reduce should be a separate commit. |
@@ -30,6 +30,9 @@ Enhancements | |||
|
|||
- Qualify memory usage in ``DataFrame.info()`` by adding ``+`` if it is a lower bound (:issue:`8578`) | |||
|
|||
- Raise errors in certain _reduce cases where the arguments are not handled. | |||
(:issue:`8592`) |
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.
- can you also make this a bit more clear? (no mention of
_reduce
) give eg the concrete case ofnumeric_only
as an example - the second line should be aligned with
Raise ...
Ok changed the whats new text. |
Yep, better! |
let me have a look |
Another remark: shouldn't this rather be a UserWarning instead of an error? (I don't know how similar things are handled in other places in pandas) |
I think this is ok (only thing, maybe need a couple of specific cases that actually trigger this error, rather than a constructed case). can't think of any off-hand though. pls rebase / squash. |
Ok, I rebased and squashed. |
@@ -4129,7 +4129,7 @@ def any(self, axis=None, bool_only=None, skipna=True, level=None, | |||
if level is not None: | |||
return self._agg_by_level('any', axis=axis, level=level, | |||
skipna=skipna) | |||
return self._reduce(nanops.nanany, axis=axis, skipna=skipna, | |||
return self._reduce(nanops.nanany, 'any', axis=axis, skipna=skipna, |
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.
where these the only 2 that didn't pass 'name' ?
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.
There's also this line where name wasn't being passed:
https://github.com/pydata/pandas/pull/8592/files#diff-03b380f521c43cf003207b0711bac67fR4007
I think the plan is to remove the above two (any/all) in the separate PR for any/all implementation.
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.
right, I was meaning any definitions (e.g. make_stat_function etc). no answer looks like no, ok, good.
I think this is fine. @jorisvandenbossche ? |
ENH: Raise error in certain unhandled _reduce cases.
thanks! |
No description provided.