Skip to content
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

ENH: Raise error in certain unhandled _reduce cases. #8592

Merged
merged 1 commit into from
Oct 28, 2014

Conversation

staple
Copy link
Contributor

@staple staple commented Oct 21, 2014

No description provided.

@staple staple changed the title Raise error in certain unimplemented _reduce cases. BUG: Raise error in certain unimplemented _reduce cases. Oct 21, 2014
@@ -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]:
Copy link
Contributor

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)

@jreback jreback added the Error Reporting Incorrect or improved errors from pandas label Oct 21, 2014
@jreback jreback added this to the 0.15.1 milestone Oct 21, 2014
@staple
Copy link
Contributor Author

staple commented Oct 21, 2014

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.

@jreback
Copy link
Contributor

jreback commented Oct 21, 2014

pls rebase and add a doc-note in v0.15.1 enhancements (reffing this pr as it doesn't have a separate issue)

@staple staple changed the title BUG: Raise error in certain unimplemented _reduce cases. ENH: Raise error in certain unimplemented _reduce cases. Oct 22, 2014
@staple staple changed the title ENH: Raise error in certain unimplemented _reduce cases. ENH: Raise error in certain unhandled _reduce cases. Oct 22, 2014
@staple
Copy link
Contributor Author

staple commented Oct 22, 2014

Ok, rebased and added to whatsnew.

@jorisvandenbossche
Copy link
Member

@staple sorry, you will have to rebase again, I moved the whatsnew file to a subfolder

@jreback
Copy link
Contributor

jreback commented Oct 23, 2014

@staple pls squash as well, otherwise looks ok

@staple
Copy link
Contributor Author

staple commented Oct 23, 2014

Ok, rebased and squashed.

@jorisvandenbossche
Copy link
Member

minor comment: is this error message only supposed to be raised internally? Or will users also see this in some cases?
If that is the case (users will see it), I don't think it is clear as users don't know what _reduce is. If it is not the case, the enhancement entry seems not very interesting for users (not to say that the PR would not be interesting of course!)

@staple
Copy link
Contributor Author

staple commented Oct 23, 2014

@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?

@jorisvandenbossche
Copy link
Member

Would it be possible to detect in which kind of aggregation function this is called?

@staple
Copy link
Contributor Author

staple commented Oct 23, 2014

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?

@jorisvandenbossche
Copy link
Member

I just wanted to suggest the same!

@staple
Copy link
Contributor Author

staple commented Oct 23, 2014

Ok, cool.

@jorisvandenbossche
Copy link
Member

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 _make_stat_function, name is not an optional argument, so it would always be present (but you should look if it is used in other places)

@staple
Copy link
Contributor Author

staple commented Oct 23, 2014

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

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 of numeric_only as an example
  • the second line should be aligned with Raise ...

@staple
Copy link
Contributor Author

staple commented Oct 23, 2014

Ok changed the whats new text.

@jorisvandenbossche
Copy link
Member

Yep, better!
@jreback OK with you that name is now a required positional arg of _reduce?

@jreback
Copy link
Contributor

jreback commented Oct 23, 2014

let me have a look

@jorisvandenbossche
Copy link
Member

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)
Also, if we raise an error and not a warning, we should maybe keep this for 0.16 instead of 0.15.1?

@jreback
Copy link
Contributor

jreback commented Oct 24, 2014

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.

@staple
Copy link
Contributor Author

staple commented Oct 26, 2014

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,
Copy link
Contributor

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' ?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@jreback
Copy link
Contributor

jreback commented Oct 26, 2014

I think this is fine. @jorisvandenbossche ?

jreback added a commit that referenced this pull request Oct 28, 2014
ENH: Raise error in certain unhandled _reduce cases.
@jreback jreback merged commit 211c80c into pandas-dev:master Oct 28, 2014
@jreback
Copy link
Contributor

jreback commented Oct 28, 2014

thanks!

@jreback jreback modified the milestones: 0.15.2, 0.15.1 Oct 30, 2014
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants