rtosholdings / riptable

64bit multithreaded python data analytics tools for numpy arrays and datasets
https://riptable.readthedocs.io/en/stable/
Other
372 stars 22 forks source link

Support for empty lists in .isin() #271

Open OrestZborowski-SIG opened 2 years ago

OrestZborowski-SIG commented 2 years ago

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 commented 2 years ago

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