-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
BUG: Errors caused by DataFrame.all(..., skipna=False, ...) in rows without na values. #41079
Comments
Thanks for the report @carsten0202! There's definitely some weird behavior here. For the first case you give, the issue that's occurring is that the call essentially gets dispatched to
So that behavior is strange, but somewhat correct, pending the tricky discussion of how to handle For the second example, when using the new nullable boolean type, the goal is to follow Kleene logic (https://pandas.pydata.org/docs/user_guide/boolean.html#kleene-logical-operations) That's somewhat complicated in the example you give because the aggregation is over The case that should be easier to handle is aggregating directly over columns, eg |
The case of |
Thanks for your feedback. I think I finally understand what the 'bool_only' option does :-) And thanks for the link to Kleene logic. I hadn't found that page, but it was very interesting. Just to update/re-iterate, then if I follow the Kleene logic correctly, the expected outcome for case 2 (df2) should be: df2.all(axis=1, skipna=False)
0 False
1 <NA>
2 False |
Yep, exactly! |
This bug still exists on version 1.4.0. Moreover, the docstring is confusing as "bool" and "boolean" are two different types in pandas.
For the examples above, we would expect the same results whether
df2.all(axis=1, skipna=True, bool_only=True)
0 True
1 True
2 True
dtype: bool Expected only when df2.all(axis=1, skipna=True, bool_only=False)
0 False
1 True
2 False
dtype: bool Expected. df2.all(axis=1, skipna=False, bool_only=False) raises df2.all(axis=1, skipna=False, bool_only=None)
0 True
1 True
2 True
dtype: bool Expect |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
I'm familiar with several issues being reported relating to skipna=False, but I have not seen this particular problem elsewhere. In short, the 'skipna=False' setting causes errors in rows not having any missing values.
Code Sample, a copy-pastable example
Problem description
With df1 row '0' is clearly wrong; with df2 '0' and '2' are undeniably wrong. The rest are imho also suspicious, but they at least follow the documented behavior of:
...even if I do believe the mathematically correct answers are as given e.g. here:
https://www.ibm.com/docs/en/spss-statistics/SaaS?topic=command-missing-values-logical-operators-if
In other words, row '1' should, imho, evaluate to 'NA'.
Expected Output
Rows '0' and '2' should clearly evaluate to 'False'.
Row '1' should maybe evaluate to 'NA'.
INSTALLED VERSIONS
commit : 2cb9652
python : 3.9.2.final.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-957.12.2.el7.x86_64
Version : #1 SMP Fri Apr 19 21:09:07 UTC 2019
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : C
LANG : C
LOCALE : None.None
pandas : 1.2.4
numpy : 1.20.1
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 49.6.0.post20210108
Cython : None
pytest : 6.2.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : None
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: