BUG: drop_duplicates fails on pyarrow string series created with convert_dtypes · Issue #54904 · pandas-dev/pandas (original) (raw)
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
This works fine
s = pd.Series(['A', 'A'], dtype='string[pyarrow]') s.drop_duplicates() 0 A dtype: string
However, this raises a NotImplementedError
s = pd.Series(['A', 'A']).convert_dtypes(dtype_backend='pyarrow') s.drop_duplicates()
Traceback (most recent call last):
File "", line 1, in
File ".../.venv/lib/python3.10/site-packages/pandas/core/series.py", line 2397, in drop_duplicates
result = super().drop_duplicates(keep=keep)
File ".../.venv/lib/python3.10/site-packages/pandas/core/base.py", line 1362, in drop_duplicates
duplicated = self._duplicated(keep=keep)
File ".../.venv/lib/python3.10/site-packages/pandas/core/base.py", line 1368, in _duplicated
return algorithms.duplicated(self._values, keep=keep)
File ".../.venv/lib/python3.10/site-packages/pandas/core/algorithms.py", line 1002, in duplicated
values = values._to_masked() # type: ignore[union-attr]
File ".../.venv/lib/python3.10/site-packages/pandas/core/arrays/arrow/array.py", line 1964, in _to_masked
raise NotImplementedError
NotImplementedError
Issue Description
This appears to be a regression in 2.1.0 as I can't reproduce in 2.0.3.
Expected Behavior
The drop_duplicates
method should work regardless of how the pyarrow string series is created.
Installed Versions
INSTALLED VERSIONS
commit : ba1cccd
python : 3.10.10.final.0
python-bits : 64
OS : Darwin
OS-release : 22.5.0
Version : Darwin Kernel Version 22.5.0: Mon Apr 24 20:51:50 PDT 2023; root:xnu-8796.121.2~5/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 2.1.0
numpy : 1.25.2
pytz : 2023.3
dateutil : 2.8.2
setuptools : 68.1.2
pip : 23.2.1
Cython : None
pytest : 7.4.0
hypothesis : None
sphinx : 7.1.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.7
jinja2 : 3.1.2
IPython : 8.14.0
pandas_datareader : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : 2023.1.0
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 13.0.0
pyreadstat : None
pyxlsb : None
s3fs : 2023.1.0
scipy : None
sqlalchemy : 2.0.20
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None