Repository navigation
Fixes Series comparison to NumPy scalars - #3436
Conversation
|
Thank you for taking this on @jrbourbeau ! @philippjfr does this resolve your original issue? |
|
The original regression test I added was using the |
|
It looks like there are some genuine testing errors in travis-ci. I suspect that this fix works for some versions, but not others. |
|
It looks like the NumPy 1.11.0 tests on Travis are failing because I've only modified |
|
Looks like there was an issue during the installation process on some of the Travis tests (see https://travis-ci.org/dask/dask/jobs/371219552#L827-L832). Could someone please restart the failed builds? |
|
Done
…On Wed, Apr 25, 2018 at 4:36 PM, James Bourbeau ***@***.***> wrote:
Looks like there was an issue during the installation process on some of
the Travis tests (see https://travis-ci.org/dask/
dask/jobs/371219552#L827-L832). Could someone please restart the failed
builds?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#3436 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszC1peBFOtr0vwRmaY6xgsQafCqjZks5tsN5UgaJpZM4ThuME>
.
|
|
cc @TomAugspurger for review if he has time |
TomAugspurger
left a comment
There was a problem hiding this comment.
Just one extremely minor nitpick, and one question :)
Does the same wrapping need to be applied to dd.Index?
| for x in inputs + out: | ||
| if not isinstance(x, (Number, Scalar, _Frame, Array, | ||
| pd.DataFrame, pd.Series, pd.Index)): | ||
| # Want to check for 0-dimensional arrays |
There was a problem hiding this comment.
Nitpick: it'd be nice if the comment explained why we're doing this, instead of what we're doing.
There was a problem hiding this comment.
That's a fair point. I can update it to something like:
# ufuncs work with 0-dimensional NumPy ndarrays
# so we don't want to raise NotImplemented| def __array_wrap__(self, array, context=None): | ||
| if isinstance(context, tuple) and len(context) > 0: | ||
| index = context[1][0].index | ||
| if isinstance(context[1][0], np.ndarray) and context[1][0].shape == (): |
There was a problem hiding this comment.
This is getting close to enough code where we might want to refactor it to a base method. In pandas this would be a _shallow_copy. You pass it the data, and the result is constructed with all the metadata and indexes.
For now though, it's probably fine.
Just to clarify, do you mean that TypeError: len() of unsized object |
|
I was just checking and it seems like things already work fine? In [1]: import numpy as np
In [2]: import dask.dataframe as dd
In [3]: import pandas as pd
In [4]: df = dd.from_pandas(pd.Series([1, 2, 3], index=[0, 2, 3]), 2)
In [5]: (df.index + np.array(1)).compute()
Out[5]: Int64Index([1, 3, 4], dtype='int64')Maybe add a test to verify that things stay fine. |
|
How about |
|
Ah that return TypeError, from a NotImplemented.
…On Thu, Apr 26, 2018 at 1:54 PM, Martin Durant ***@***.***> wrote:
How about (np.array(1) + df.index).compute()
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3436 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABQHIvatWdzmh5BdJaXy9N2mSadSlMMQks5tshf4gaJpZM4ThuME>
.
|
|
Hmmmm I'm able to reproduce Tom's example. I.e. import numpy as np
import dask.dataframe as dd
import pandas as pd
df = dd.from_pandas(pd.Series([1, 2, 3], index=[0, 2, 3]), 2)
print((df.index + np.array(1)).compute())Gives But reversing the addition order changes behavior depending on which numpy version I'm using.
I take it this difference has to do with the fact that |
|
Checking in here. What is the status of this? |
|
Haven't looked closely, but I think everything I looked at last time was fine. I'd be happy with merging this as is, and opening a separate issue to track the (presumably less common) ops on the Index class, if there's even an issue there. |
|
Just updated comment as per Tom's suggestion |
|
Great. This is in. Thanks @jrbourbeau ! |
Fixes #3392. This PR fixes Series comparison to NumPy scalars, which currently fail.
flake8 daskdocs/source/changelog.rstfor all changesand one of the
docs/source/*-api.rstfiles for new API