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: groupby.rank is not supported for large_string[pyarrow] dtype #59088

Open
2 of 3 tasks
cvm-a opened this issue Jun 24, 2024 · 2 comments
Open
2 of 3 tasks

BUG: groupby.rank is not supported for large_string[pyarrow] dtype #59088

cvm-a opened this issue Jun 24, 2024 · 2 comments
Assignees
Labels
Arrow pyarrow functionality Bug Groupby Strings String extension data type and string data

Comments

@cvm-a
Copy link

cvm-a commented Jun 24, 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 pyarrow as pa

df = pd.DataFrame(
  {
    "a": list(range(10)) * 2,
    "b":list(range(20,30)) * 2,
    "c":list(range(50,70)),
  },
 dtype=pd.ArrowDtype(pa.string())
)

result = df2.groupby(["a", "b"], as_index=False)["c"].rank(method="first", ascending=False, na_option="bottom")

Issue Description

This is similar to #51996. When grouping a dataframe and applying the rank function on a column with data type string[pyarrow] or large_string[pyarrow] I get the following error:
TypeError: rank is not supported for string[pyarrow] dtype
or
TypeError: rank is not supported for large_string[pyarrow] dtype
respectively

Expected Behavior

I would expect rank to work for string[pyarrow] just as it works for the pandas "string" dtype, using lexicographic ordering.

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.11.6.final.0
python-bits : 64
OS : Darwin
OS-release : 23.5.0
Version : Darwin Kernel Version 23.5.0: Wed May 1 20:14:38 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6020
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.2
numpy : 1.24.4
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 70.0.0
pip : 23.2.1
Cython : 3.0.10
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.2.0
lxml.etree : 5.2.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.4
IPython : 8.24.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.5.0
gcsfs : 2024.5.0
matplotlib : 3.9.0
numba : 0.57.1
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 16.1.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.13.1
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : 2.0.1
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

@cvm-a cvm-a added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 24, 2024
@mroeschke mroeschke changed the title BUG: rank is not supported for large_string[pyarrow] dtype BUG: groupby.rank is not supported for large_string[pyarrow] dtype Jul 8, 2024
@mroeschke mroeschke added Groupby Strings String extension data type and string data Arrow pyarrow functionality and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 8, 2024
@mroeschke
Copy link
Member

Thanks for the report. Currently groupby ops in pandas are all numpy based, so arrow types are converted to numpy first using _to_masked. Looks like there currently no conversion in that method to "numpy strings".

@chaarvii
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality Bug Groupby Strings String extension data type and string data
Projects
None yet
Development

No branches or pull requests

3 participants