Skip to content

BUG: reducing ufuncs don't return a scalar #23312

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
jorisvandenbossche opened this issue Oct 24, 2018 · 5 comments
Closed

BUG: reducing ufuncs don't return a scalar #23312

jorisvandenbossche opened this issue Oct 24, 2018 · 5 comments
Labels
Bug Compat pandas objects compatability with Numpy or Python functions
Milestone

Comments

@jorisvandenbossche
Copy link
Member

But are wrapped again in the Series or Index:

In [1]: s = pd.Series([1, 2, 3])

In [3]: np.add.reduce(s)
Out[3]: 
0    6
1    6
2    6
dtype: int64

In [4]: np.add.reduce(s.values)
Out[4]: 6
@jorisvandenbossche jorisvandenbossche added Bug Compat pandas objects compatability with Numpy or Python functions labels Oct 24, 2018
@jorisvandenbossche jorisvandenbossche added this to the 0.24.0 milestone Oct 24, 2018
@jorisvandenbossche
Copy link
Member Author

And for index it is even worse:

In [16]: idx = pd.Index([1, 2, 3])

In [17]: result = np.add.reduce(idx)

In [18]: result    # <-- repr is failing
...
TypeError: len() of unsized object

In [19]: type(result)
Out[19]: pandas.core.indexes.numeric.Int64Index

In [20]: result.values
Out[20]: array(6)

@jorisvandenbossche
Copy link
Member Author

@shoyer I thought to fix this first / separately before the __array_ufunc__ PR, but, the behaviour here is a little bit undefined.
I suppose that in principle, a ufunc.reduce returns an array (or an object of the same array-like) with a reduced dimension. But in pandas, we of couse don't have a concept of 0-dim objects or in general variable dim objects. So I assume returning a 0-dim array is fine here (or just a scalar?), but seems a bit strange to ask this of an ExtensionArray (there a scalar might make more sense if it's something that otherwise needs to be wrapped in a 0-dim object array?).

@jreback jreback modified the milestones: 0.24.0, Contributions Welcome Nov 25, 2018
@jorisvandenbossche
Copy link
Member Author

@TomAugspurger I think this was closed by #23293 ?

@jorisvandenbossche jorisvandenbossche modified the milestones: Contributions Welcome, 0.25.0 Aug 8, 2019
@jorisvandenbossche
Copy link
Member Author

on master

In [63]: s = pd.Series([1, 2, 3])                                                                                                                                                             

In [64]: np.add.reduce(s)                                                                                                                                                                     
Out[64]: 6

@TomAugspurger
Copy link
Contributor

Looks like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Compat pandas objects compatability with Numpy or Python functions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants