-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REGR: Series.__array_ufunc__ doesn't handle .outer
#27186
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
Comments
It could indeed be a DataFrame. (I first wanted to say: that's only possible if both inputs are a Series, otherwise you don't have labels for the columns, but: inputs first get aligned, so you always get the same labels for index / columns. BTW, for outer ufuncs, in numpy you can have different lengths for both inputs, and end up with a non-square array. But since we do alignment in normal ufuncs in pandas, we should do alignment here as well I suppose. Although I would also see usefulness in a non-aligning behaviour, where the resulting index/column labels can be different. |
Hmm, apparently the inputs can be So I guess we should always return an ndarray...
Yes... I missed that. I'll make a PR. |
For reference, xarray raises In [22]: a = xr.DataArray([1, 2, 3])
In [23]: np.subtract.outer(a, a)
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-23-83caec80c9b6> in <module>
----> 1 np.subtract.outer(a, a)
~/Envs/pandas-dev/lib/python3.7/site-packages/xarray/core/arithmetic.py in __array_ufunc__(self, ufunc, method, *inputs, **kwargs)
47 'alternative, consider explicitly converting xarray objects '
48 'to NumPy arrays (e.g., with `.values`).'
---> 49 .format(method, ufunc))
50
51 if any(isinstance(o, SupportsArithmetic) for o in out):
NotImplementedError: outer method for ufunc <ufunc 'subtract'> is not implemented on xarray objects, which currently only support the __call__ method. As an alternative, consider explicitly converting xarray objects to NumPy arrays (e.g., with `.values`). Given the ambiguity about whether |
Yes, that seems like the safest option (we can later still always enable it again if there is a clear use case) |
* DEPR: Deprecate outer ufunc in Series.__array_ufunc__ Closes #27186
0.24.2
master
Probably not an RC blocker, but I may try to get a fix in quick.
Do we want to return an ndarray here? We don't want a DataFrame where the index & columns match?
cc @jorisvandenbossche @shoyer if you have thoughts on the ideal return type.
The text was updated successfully, but these errors were encountered: