Skip to content
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: dropna throws error with arguments axis=1 and subset not None #60244

Closed
2 of 3 tasks
ochabloz opened this issue Nov 8, 2024 · 2 comments
Closed
2 of 3 tasks

BUG: dropna throws error with arguments axis=1 and subset not None #60244

ochabloz opened this issue Nov 8, 2024 · 2 comments
Labels
Bug Closing Candidate May be closeable, needs more eyeballs Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

Comments

@ochabloz
Copy link

ochabloz commented Nov 8, 2024

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

import pandas as pd
import numpy as np

df = pd.DataFrame({"name": ['Alfred', 'Batman', 'Catwoman'], "toy": [np.nan, 'Batmobile', 'Bullwhip'], "born": [pd.NaT, pd.NaT,pd.NaT]})
df.dropna(axis=1, subset=['born'])

Issue Description

Traceback (most recent call last):
File "/home/vscode/.local/lib/python3.10/site-packages/pandas/core/frame.py", line 6670, in dropna
raise KeyError(np.array(subset)[check].tolist())
KeyError: ['born']

Expected Behavior

dropna should return the dataframe without the born column.

Installed Versions

commit : 0691c5c
python : 3.10.15
python-bits : 64
OS : Linux
OS-release : 6.11.5
Version : #1-NixOS SMP PREEMPT_DYNAMIC Tue Oct 22 13:51:37 UTC 2024
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.3
numpy : 1.26.4
pytz : 2024.2
dateutil : 2.9.0.post0
pip : 23.0.1
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.4
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : 8.3.3
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.14.1
sqlalchemy : 2.0.36
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2024.2
qtpy : None
pyqt5 : None

@ochabloz ochabloz added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 8, 2024
@asishm
Copy link
Contributor

asishm commented Nov 8, 2024

Thanks for the report. The error is accurate.

The documentation for the subset argument states:

subset : column label or sequence of labels, optional
Labels along other axis to consider, e.g. if you are dropping rows
these would be a list of columns to include.

Note that it mentions other axis. In this case you specify axis=1 i.e. columns, therefore for subset you need to provide row labels (but that doesn't sound like what you're after).

df.dropna(axis=1, how='all') will drop all columns where every value is na

@asishm asishm added the Closing Candidate May be closeable, needs more eyeballs label Nov 8, 2024
@rhshadrach rhshadrach removed the Needs Triage Issue that has not been reviewed by a pandas team member label Nov 8, 2024
@rhshadrach
Copy link
Member

Agreed @asishm - closing.

@rhshadrach rhshadrach added the Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Closing Candidate May be closeable, needs more eyeballs Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

No branches or pull requests

3 participants