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

ENH: ndarray.isin #20092

Open
MaxGhenis opened this issue Oct 11, 2021 · 1 comment
Open

ENH: ndarray.isin #20092

MaxGhenis opened this issue Oct 11, 2021 · 1 comment

Comments

@MaxGhenis
Copy link

MaxGhenis commented Oct 11, 2021

Proposed new feature or change:

numpy.isin is equivalent to pandas.{Series,DataFrame}.isin. Adding numpy.ndarray.isin would produce consistency with pandas and save 4 characters:

np.isin(x, y)  # Current
x.isin(y)      # Proposed

I've posted this idea to the forum here.

@adeak
Copy link
Contributor

adeak commented Oct 11, 2021

There are plenty of numpy functions that aren't ndarray methods but are pandas.Series methods:

>>> import numpy as np
>>> import pandas as pd
>>> series_methods = [attr for attr in dir(pd.Series) if callable(getattr(pd.Series, attr))]
>>> array_methods = [attr for attr in dir(np.ndarray) if callable(getattr(np.ndarray, attr))]
>>> setdiff = set(series_methods) - set(array_methods)
>>> [attr for attr in dir(np) if attr in setdiff]
['__getattr__', 'abs', 'add', 'append', 'cov', 'diff', 'divide', 'divmod', 'isin', 'median', 'mod', 'multiply', 'pad', 'product', 'quantile', 'subtract', 'unique', 'where']

Numpy devs are usually very reluctant to inflate the ndarray namespace. And there are a lot of more commonly useful methods in that list, for instance np.diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants