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

Support for empty lists in .isin() #271

Open
OrestZborowski-SIG opened this issue Dec 8, 2021 · 1 comment
Open

Support for empty lists in .isin() #271

OrestZborowski-SIG opened this issue Dec 8, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@OrestZborowski-SIG
Copy link
Contributor

Would it be possible to add support for empty lists to the .isin() function, so that .isin([]) returns a filter that’s identically false? Seems like an edge case that would be worth having – I just ran into it in my code where I have a filter like ~ds.col.isin(bad_value_list) to exclude bad values, and found it gave an error on a dataset that didn’t have any bad values to exclude.

From a cursory look at the code that appears pretty straightforward to do; right now the end of the .isin() function has

        if isinstance(x, (list, np.ndarray)):
            if len(x) > 1:
                return ismember(self, x)[0]
            elif np.isscalar(x[0]):
                return self == x[0]

If len(x) = 0 it hits an error at the “elif np.isscalar(x[0])” line, so I think you could just put an “elif len(x) == 0” before that which has it return a FA of False of the same length as self.

@OrestZborowski-SIG OrestZborowski-SIG added the enhancement New feature or request label Dec 8, 2021
@OrestZborowski-SIG
Copy link
Contributor Author

This would match behavior of numpy.isin(arr, [])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant