Skip to content

BUG: does .any(axis=1, skipna=False) follow Kleene Logic? #57171

Open
@MarcoGorelli

Description

@MarcoGorelli

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

In [16]: pd.DataFrame({
    ...:     'a': [True, False, None],
    ...:     'b': [None, None, None],
    ...: }, dtype='boolean[pyarrow]').any(axis=1, skipna=False)
Out[16]:
0     True  #
1    False  # <=== should be NA?
2    False  # <=== should be NA?
dtype: bool[pyarrow]


In [17]: pd.Series([False, None], dtype='boolean[pyarrow]').any(skipna=False)
Out[17]: <NA>

In [18]: pd.Series([None, None], dtype='boolean[pyarrow]').any(skipna=False)
Out[18]: <NA>

In [19]: pd.Series([True, None], dtype='boolean[pyarrow]').any(skipna=False)
Out[19]: True

Issue Description

I don't really understand what's happening, nor what's meant to be happening

The docs for Series.any say

If skipna is False, then NA are treated as True, because these are not equal to zero.

but that doesn't seem to be the case. If that was the case, then

pd.Series([False, None], dtype='boolean[pyarrow]').any(skipna=False)

would return True?

Instead, it looks like Series.any follows Kleene Logic. Fair nuff - but then, DataFrame.any(axis=1, skipna=False) doesn't?

Expected Behavior

I think I'd expect

0     True
1     <NA>
2     <NA>

from the DataFrame.any(axis=1, skipna=False) example

Installed Versions

INSTALLED VERSIONS

commit : fd3f571
python : 3.10.12.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.133.1-microsoft-standard-WSL2
Version : #1 SMP Thu Oct 5 21:02:42 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8

pandas : 2.2.0
numpy : 1.26.3
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 59.6.0
pip : 22.0.2
Cython : None
pytest : 7.4.4
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.19.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2023.12.2
gcsfs : 2023.12.2post1
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 15.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.11.4
sqlalchemy : 2.0.25
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.4
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions