pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
42.62k stars 17.57k forks source link

BUG: df.all(skipna=False) #59024

Closed nalgae73 closed 2 weeks ago

nalgae73 commented 2 weeks ago

Pandas version checks

Reproducible Example

import pandas as pd
import numpy as np

# Sample data
data = {
    'a': [np.nan, True],
}

df = pd.DataFrame(data)
print(df.all(skipna=False))

Issue Description

The DataFrame.all method returns True when skipna=False even if there are NaN values in the DataFrame. According to the documentation, NaN values should be considered as False when skipna=False.

Expected Behavior

Expected output: False, but it returns True

Installed Versions

INSTALLED VERSIONS ------------------ commit : d9cdd2ee5a58015ef6f4d15c7226110c9aab8140 python : 3.11.8.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.19045 machine : AMD64 processor : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : Korean_Korea.949 pandas : 2.2.2 numpy : 1.26.4 pytz : 2024.1 dateutil : 2.9.0.post0 setuptools : 68.2.2 pip : 23.3.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 3.1.3 IPython : None pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : None bottleneck : 1.3.7 dataframe-api-compat : None fastparquet : None fsspec : 2023.10.0 gcsfs : None matplotlib : 3.8.4 numba : None numexpr : 2.8.7 odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : 1.13.0 sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None zstandard : None tzdata : 2023.3 qtpy : None pyqt5 : None Process finished with exit code 0
asishm commented 2 weeks ago

Where do you see in the docs that NaN values should be considered False?

the docs I see states:

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

nalgae73 commented 2 weeks ago

skipna : bool, default True Exclude NA/null values. If the entire row/column is NA and skipna is True, then the result will be True, as for an empty row/column. If skipna is False, then NA are treated as True, because these are not equal to zero.

I mismemorized. Thank you asishm.