-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: pd.isnull
treats list
and tuple
input differently
#52283
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
Comments
This function returns a boolean or array-like of bool. I'll keep the "bug" label just in case, but I don't think it is one. https://pandas.pydata.org/docs/reference/api/pandas.isnull.html |
Thanks @DeaMariaLeon. The thing that seems off to me is In [1]: import pandas as pd
In [2]: pd.isnull([1, pd.NA, 3])
Out[2]: array([False, True, False])
In [3]: pd.isnull((1, pd.NA, 3))
Out[3]: False My expectation is that both lists and tuples should be treated as array-like. Though feel free to let me know if that expectation is incorrect |
Oh, I see! Thank you for opening an issue. :) |
This is an edge case I think. You can end up with tuples from a MultiIndex for example. In this scenario we want to treat the tuple as a single element, e.g.
treats the tuple as a single element. I think this is similar here although it does not really look intuitive to me either. |
Interestingly in a list, tuples are treated as array-like:
|
As far as I remember, in the past we made this distinction (in certain places) because tuples can be labels, as Patrick mentioned. But it's indeed a tricky situation, with easy confusion and corner cases (a quick search for "tuple list label" gives quite some related issues). For example #43978 for the drop example. Another example in indexing where the two are distinguished and have different behaviour: >>> s = pd.Series(range(6), index=pd.MultiIndex.from_product([[1, 2, 3], [1, 2]]))
>>> s.loc[(1, 2)] # tuple is a single label
1
>>> s.loc[[1, 2]] # list is an indexer (in this case for the first level of the MultiIndex)
1 1 0
2 1
2 1 2
2 3
dtype: int64 |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
It looks like
pd.isnull
is treatinglist
as array-like andtuple
as a scalarExpected Behavior
I'd expect
list
s andtuple
s to be treated similarly bypd.isnull
. Similar to other parts of the API likepd.Series
Installed Versions
The text was updated successfully, but these errors were encountered: