-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Isin #2031
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
Isin #2031
Changes from all commits
45dfadd
a8fbe2b
267f02c
4411abe
bcaaaf7
ffa5e1d
a183c46
75493c2
4da73c6
6fb9c48
616db23
60fbd5b
34dabe1
0cc1752
41d73b0
8398858
416e67d
581b3c2
0a24429
f1768cd
80557c5
d9c9907
9c78417
dd0136d
43532df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3327,6 +3327,14 @@ def da(request): | |
[0, np.nan, 1, 2, np.nan, 3, 4, 5, np.nan, 6, 7], | ||
dims='time') | ||
|
||
if request.param == 'repeating_ints': | ||
return DataArray( | ||
np.tile(np.arange(12), 5).reshape(5, 4, 3), | ||
coords={'x': list('abc'), | ||
'y': list('defg')}, | ||
dims=list('zyx') | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def da_dask(seed=123): | ||
|
@@ -3339,6 +3347,31 @@ def da_dask(seed=123): | |
return da | ||
|
||
|
||
@pytest.mark.skipif(LooseVersion(np.__version__) < LooseVersion('1.13.0'), | ||
reason='requires numpy version 1.13.0 or later') | ||
@pytest.mark.parametrize('da', ('repeating_ints', ), indirect=True) | ||
def test_isin(da): | ||
|
||
expected = DataArray( | ||
np.asarray([[0, 0, 0], [1, 0, 0]]), | ||
dims=list('yx'), | ||
coords={'x': list('abc'), | ||
'y': list('de')}, | ||
).astype('bool') | ||
|
||
result = da.isin([3]).sel(y=list('de'), z=0) | ||
assert_equal(result, expected) | ||
|
||
expected = DataArray( | ||
np.asarray([[0, 0, 1], [1, 0, 0]]), | ||
dims=list('yx'), | ||
coords={'x': list('abc'), | ||
'y': list('de')}, | ||
).astype('bool') | ||
result = da.isin([2, 3]).sel(y=list('de'), z=0) | ||
assert_equal(result, expected) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add another test for the dask path, e.g., that calls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (done in |
||
|
||
@pytest.mark.parametrize('da', (1, 2), indirect=True) | ||
def test_rolling_iter(da): | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably a better idea to explicitly unwrap
.data
fromtest_elements
if it's an xarray object, and explicitly raise forxarray.Dataset
. Otherwise numpy will probably give a really strange error message.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, see #2032 for what converting a Dataset to a numpy array does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I merged your branch - is that better than an additional check?
Why extract
.data
- won't the standard machinery take care of that? I added a testThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose you're right, the standard machinery will work fine here for now. In the future when dask supports isin (dask/dask#3363) we'll want to use
.data
so we can keep it as a dask array.