Repository navigation
isin: better docs, support older numpy and use dask.array.isin. - #2038
Merged
Merged
Conversation
I added a section to the indexing docs showing how to use `isin` with `where` to do idnexing. Adding support for older numpy turned out to be pretty easy, so I added a copy of np.isin in npcompat. This PR also makes use of dask.array.isin, so that we can support a dask array properly as the second argument: dask/dask#3363
stickler-ci
reviewed
Apr 5, 2018
| mapped = da.atop(_isin_kernel, element_axes + test_axes, | ||
| element, element_axes, | ||
| test_elements, test_axes, | ||
| adjust_chunks={axis: lambda _: 1 for axis in test_axes}, |
Contributor
There was a problem hiding this comment.
E501 line too long (81 > 79 characters)
|
|
||
| def isin(element, test_elements, assume_unique=False, invert=False): | ||
| """ | ||
| Calculates `element in test_elements`, broadcasting over `element` only. |
Contributor
There was a problem hiding this comment.
E501 line too long (80 > 79 characters)
| """ | ||
| Calculates `element in test_elements`, broadcasting over `element` only. | ||
| Returns a boolean array of the same shape as `element` that is True | ||
| where an element of `element` is in `test_elements` and False otherwise. |
Contributor
There was a problem hiding this comment.
E501 line too long (80 > 79 characters)
|
|
||
| `isin` is an element-wise function version of the python keyword `in`. | ||
| ``isin(a, b)`` is roughly equivalent to | ||
| ``np.array([item in b for item in a])`` if `a` and `b` are 1-D sequences. |
Contributor
There was a problem hiding this comment.
E501 line too long (81 > 79 characters)
|
|
||
| `element` and `test_elements` are converted to arrays if they are not | ||
| already. If `test_elements` is a set (or other non-sequence collection) | ||
| it will be converted to an object array with one element, rather than an |
Contributor
There was a problem hiding this comment.
E501 line too long (80 > 79 characters)
| """ | ||
| element = np.asarray(element) | ||
| return np.in1d(element, test_elements, assume_unique=assume_unique, | ||
| invert=invert).reshape(element.shape) No newline at end of file |
Contributor
There was a problem hiding this comment.
W292 no newline at end of file
Collaborator
|
Looks great!! Thank you |
max-sixty
approved these changes
Apr 5, 2018
| def test_isin_dataset(): | ||
| ds = Dataset({'x': [1, 2]}) | ||
| with pytest.raises(TypeError): | ||
| ds.isin(ds) |
Collaborator
There was a problem hiding this comment.
You're right, this wasn't really an xfail
| which test each value in the array for whether it is contained in the | ||
| supplied list, returning a bool array. See :ref:`selecting values with isin` | ||
| for full details. Similar to the ``np.isin`` function. | ||
| By `Maximilian Roos <https://github.com/maxim-lian>`_. |
Collaborator
There was a problem hiding this comment.
Feel free to change! Thank you for adding the docs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I added a section to the indexing docs showing how to use
isinwithwhereto do indexing.Adding support for older numpy turned out to be pretty easy, so I added a copy of np.isin in npcompat.
This PR also makes use of dask.array.isin, so that we can support a dask array properly as the second argument:
dask/dask#3363