Skip to content
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: better docs, support older numpy and use dask.array.isin. #2038

Merged
merged 4 commits into from Apr 6, 2018

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented Apr 5, 2018

I added a section to the indexing docs showing how to use isin with where to 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

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
@shoyer shoyer requested a review from max-sixty April 5, 2018 05:31
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},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W292 no newline at end of file

@max-sixty
Copy link
Collaborator

Looks great!! Thank you

def test_isin_dataset():
ds = Dataset({'x': [1, 2]})
with pytest.raises(TypeError):
ds.isin(ds)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>`_.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to change! Thank you for adding the docs

@shoyer shoyer merged commit 6402391 into pydata:master Apr 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants