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: Pandas 1.4; df.drop method raises an AttributeError when Int64 index is used and index is not unique #45860

Closed
2 of 3 tasks
JeremyVriens opened this issue Feb 7, 2022 · 3 comments · Fixed by #45983
Closed
2 of 3 tasks
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays. Index Related to the Index class or subclasses Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@JeremyVriens
Copy link

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

df = pd.DataFrame({"i": pd.Series([1, 2, 2], dtype=pd.Int64Dtype())}).set_index("i")
idx = pd.Index([2])
df.drop(idx)  # Raises AttributeError here

Issue Description

An exception AttributeError: 'BooleanArray' object has no attribute 'nonzero' is raised when the index is Int64 and not unique.

https://github.com/pandas-dev/pandas/blob/main/pandas/core/generic.py#L4345 mask is a BooleanArray here instead of an ndarray when the Index is not unique and of dtype Int64.

It got introduced in 1.4 with this PR: #43760

Expected Behavior

No exception should be raised.

Installed Versions

INSTALLED VERSIONS ------------------ commit : bb1f651 python : 3.8.6.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.19041 machine : AMD64 processor : Intel64 Family 6 Model 85 Stepping 4, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : English_United States.1252 pandas : 1.4.0 numpy : 1.22.1 pytz : 2021.3 dateutil : 2.8.2 pip : 22.0.3 setuptools : 59.8.0 Cython : None pytest : 6.2.5 hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 3.0.3 IPython : 8.0.1 pandas_datareader: None bs4 : None bottleneck : None fastparquet : None fsspec : None gcsfs : None matplotlib : None numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : None sqlalchemy : 1.4.31 tables : None tabulate : None xarray : None xlrd : None xlwt : None zstandard : None
@JeremyVriens JeremyVriens added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 7, 2022
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Feb 8, 2022
@simonjayhawkins
Copy link
Member

Thanks @JeremyVriens for the report

It got introduced in 1.4 with this PR: #43760

first bad commit: [e750c94] ENH: allow storing ExtensionArrays in Index (#43930)

@simonjayhawkins
Copy link
Member

cc @jbrockmendel

@simonjayhawkins simonjayhawkins added this to the 1.4.1 milestone Feb 8, 2022
@simonjayhawkins simonjayhawkins added Regression Functionality that used to work in a prior pandas version ExtensionArray Extending pandas with custom dtypes or arrays. Index Related to the Index class or subclasses and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 8, 2022
@jbrockmendel
Copy link
Member

yah its on my radar screen. pd.NA propagation is a PITA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays. Index Related to the Index class or subclasses Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants