Skip to content

ENH: maybe_dispatch_to_dunder_op handle min/max #31219

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

Closed
jbrockmendel opened this issue Jan 22, 2020 · 4 comments
Closed

ENH: maybe_dispatch_to_dunder_op handle min/max #31219

jbrockmendel opened this issue Jan 22, 2020 · 4 comments

Comments

@jbrockmendel
Copy link
Member

I'm running up against a case where I need np.maximum.reduce(period_array) to work; itd be nice if that could be handled by maybe_dispatch to call PeriodArray.max

cc @jorisvandenbossche @TomAugspurger

@TomAugspurger
Copy link
Contributor

To clarify, np.maximum(PeriodArray) works fine, right? It's the .reduce part that isn't handled?

@jbrockmendel
Copy link
Member Author

np.maximum(PeriodArray) breaks because it expects multiple arguments, np.maximum(period_array, period_array) works, while np.maximum(period_index, period_index) fails with ValueError: ufunc 'maximum' not supported for the PeriodIndex

But yes, it is specifically the .reduce that is coming up at the moment

@TomAugspurger
Copy link
Contributor

while np.maximum(period_index, period_index) fails with ValueError: ufunc 'maximum' not supported for the PeriodIndex

That would be solved with Index having an __array_ufunc__. I wounder if Series.__array_ufunc__ can be moved to to IndexOpsMixin. I suppose alignment of Series but not Index makes that tricky.

Can you provide a failing example for reduce on period array?

In [8]: np.maximum.reduce(pd.array(['2000', '2001'], dtype='Period[D]'))
Out[8]: Period('2001-01-01', 'D')

@jbrockmendel
Copy link
Member Author

Can you provide a failing example for reduce on period array?

Not on master. In the relevant branch I have implemented DatetimeLikeArrayMixin.__array_ufunc__ (to get np.isfinite(datetimeindex_tzaware) to work... yak shaving)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants