-
-
Notifications
You must be signed in to change notification settings - Fork 132
Add XArray compatibility features #102
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
Tests not yet added. |
Unfortunately, there doesn't seem to be a way to override >>> import numpy as np
>>> import sparse
>>> x = np.asarray([5, 6, np.nan])
>>> s = sparse.COO.from_numpy(x)
>>> s.nansum()
nanreduce
11.0
>>> np.nansum(s)
11.0 Edit: It doesn't want to fall back to our implementation even if we err when coercing. >>> class NoncoercibleCOO(sparse.COO):
... def __array__(self, *args, **kwargs):
... raise ValueError('Cannot coerce COO.')
...
>>> s = NoncoercibleCOO.from_numpy(x)
>>> np.nansum(s)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Users/hameer/anaconda3/envs/sparse/lib/python3.6/site-packages/numpy/lib/nanfunctions.py", line 581, in nansum
a, mask = _replace_nan(a, 0)
File "/Users/hameer/anaconda3/envs/sparse/lib/python3.6/site-packages/numpy/lib/nanfunctions.py", line 64, in _replace_nan
a = np.array(a, subok=True, copy=True)
File "<input>", line 3, in __array__
ValueError: Cannot coerce COO. |
Hmm. It seems that (for In any case, I'm willing to leave this as an xfail for now. Any input welcome. |
Do we want to support the edge case of NaNs in object arrays? It's proving difficult. It's certainly possible, but only with a bit of trickery. |
Make a test with pytest.mark.xfail and move on?
…On Tue, Feb 20, 2018 at 4:08 PM, Hameer Abbasi ***@***.***> wrote:
Do we want to support the edge case of NaNs in object arrays? It's proving
difficult.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#102 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszHNoWLT6YB86IzQaL6O_9tQ6yww2ks5tWzRGgaJpZM4SKZV8>
.
|
I don't think there are many uses for object dtype sparse arrays. Mostly we
use those for strings, but I imagine sparse arrays are most useful for
numbers.
…On Tue, Feb 20, 2018 at 1:09 PM Hameer Abbasi ***@***.***> wrote:
Do we want to support the edge case of NaNs in object arrays? It's proving
difficult.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#102 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABKS1lF-wLH1pZ4iTlLns0ZNY24qywqnks5tWzRGgaJpZM4SKZV8>
.
|
It seems we don't support object arrays in many cases at the moment. I've opened #104 to track this but am inclined to ignore this. |
I fixed the Edit: I looked at the implementation for |
This looks good to me :) |
Merged! |
* Implement where. * Implement NaN-skipping aggregations. * Docs. * Add tests, clarify docs a bit. * Move NaN aggregations to be functions rather than methods to match Numpy * Get rid of eval that was bothering me a lot. * Fix NaN inequality issue. * Remove object dtype code. * Test for and fix warning code.
Once the right broadcasting setup was in place; it was trivial to implement the three-argument version of
where
and NaN-skipping aggregations.cc @mrocklin Feedback welcome.
cc @shoyer Feedback really welcome, as you know the ins and outs of XArray. Of course, "I can't" is okay; as always. :-)