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: Failures with ArrowDtype(pa.string_view()) #60068

Open
2 of 3 tasks
a10y opened this issue Oct 18, 2024 · 2 comments
Open
2 of 3 tasks

BUG: Failures with ArrowDtype(pa.string_view()) #60068

a10y opened this issue Oct 18, 2024 · 2 comments
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@a10y
Copy link

a10y commented Oct 18, 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 # pandas 2.2.3 => latest
import pyarrow as pa # pyarrow 17.0.0 => latest

tab = pa.table({"names": pa.array(["a", "b", "c"], type=pa.string_view())})

# this succeeds
tab.to_pandas()

# this throws an exception
tab.to_pandas(types_mapper=pd.ArrowDtype)

Issue Description

Our library is producing Arrow binary view arrays (strings and binary) and we want to allow users to convert into Pandas DataFrame.

We are using the pd.ArrowDtype constructor to allow creating Pandas arrays that are backed with Arrow storage. The example I've attached fails also when you change "c" to None (i.e. problem hits for both nullable and non-nullable types).

Full repro with error message:

>>> import pandas as pd # pandas 2.2.3 => latest
>>> import pyarrow as pa # pyarrow 17.0.0 => latest
>>>
>>> tab = pa.table({"names": pa.array(["a", "b", "c"], type=pa.string_view())})
>>>
>>> # this succeeds
>>> tab.to_pandas()
  names
0     a
1     b
2     c
>>>
>>> # this throws an exception
>>> tab.to_pandas(types_mapper=pd.ArrowDtype)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Volumes/Code/vortex/.venv/lib/python3.11/site-packages/pandas/core/frame.py", line 1214, in __repr__
    return self.to_string(**repr_params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/Code/vortex/.venv/lib/python3.11/site-packages/pandas/util/_decorators.py", line 333, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/Code/vortex/.venv/lib/python3.11/site-packages/pandas/core/frame.py", line 1394, in to_string
    return fmt.DataFrameRenderer(formatter).to_string(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/Code/vortex/.venv/lib/python3.11/site-packages/pandas/io/formats/format.py", line 962, in to_string
    string = string_formatter.to_string()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/Code/vortex/.venv/lib/python3.11/site-packages/pandas/io/formats/string.py", line 29, in to_string
    text = self._get_string_representation()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/Code/vortex/.venv/lib/python3.11/site-packages/pandas/io/formats/string.py", line 44, in _get_string_representation
    strcols = self._get_strcols()
              ^^^^^^^^^^^^^^^^^^^
  File "/Volumes/Code/vortex/.venv/lib/python3.11/site-packages/pandas/io/formats/string.py", line 35, in _get_strcols
    strcols = self.fmt.get_strcols()
              ^^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/Code/vortex/.venv/lib/python3.11/site-packages/pandas/io/formats/format.py", line 476, in get_strcols
    strcols = self._get_strcols_without_index()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/Code/vortex/.venv/lib/python3.11/site-packages/pandas/io/formats/format.py", line 729, in _get_strcols_without_index
    str_columns = self._get_formatted_column_labels(self.tr_frame)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/Code/vortex/.venv/lib/python3.11/site-packages/pandas/io/formats/format.py", line 809, in _get_formatted_column_labels
    need_leadsp = dict(zip(fmt_columns, map(is_numeric_dtype, dtypes)))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/Code/vortex/.venv/lib/python3.11/site-packages/pandas/core/dtypes/common.py", line 1119, in is_numeric_dtype
    return _is_dtype_type(
           ^^^^^^^^^^^^^^^
  File "/Volumes/Code/vortex/.venv/lib/python3.11/site-packages/pandas/core/dtypes/common.py", line 1468, in _is_dtype_type
    tipo = pandas_dtype(arr_or_dtype).type
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/Code/vortex/.venv/lib/python3.11/site-packages/pandas/core/dtypes/dtypes.py", line 2169, in type
    raise NotImplementedError(pa_type)
NotImplementedError: string_view
>>>

This seems like a distinct issue from #59883.

Expected Behavior

I'd expect the throwing example to not throw.

Installed Versions

Device: macOS 14.4.1 M2 Max MBP

>>> pd.show_versions()

INSTALLED VERSIONS
------------------
commit                : 0691c5cf90477d3503834d983f69350f250a6ff7
python                : 3.11.9
python-bits           : 64
OS                    : Darwin
OS-release            : 23.4.0
Version               : Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020
machine               : arm64
processor             : arm
byteorder             : little
LC_ALL                : en_US.UTF-8
LANG                  : None
LOCALE                : en_US.UTF-8

pandas                : 2.2.3
numpy                 : 1.26.4
pytz                  : 2024.1
dateutil              : 2.9.0.post0
pip                   : 24.0
Cython                : None
sphinx                : 8.0.2
IPython               : 8.26.0
adbc-driver-postgresql: None
adbc-driver-sqlite    : None
bs4                   : 4.12.3
blosc                 : None
bottleneck            : None
dataframe-api-compat  : None
fastparquet           : None
fsspec                : None
html5lib              : None
hypothesis            : None
gcsfs                 : None
jinja2                : 3.1.3
lxml.etree            : None
matplotlib            : 3.9.2
numba                 : None
numexpr               : None
odfpy                 : None
openpyxl              : None
pandas_gbq            : None
psycopg2              : None
pymysql               : None
pyarrow               : 17.0.0
pyreadstat            : None
pytest                : 8.1.1
python-calamine       : None
pyxlsb                : None
s3fs                  : None
scipy                 : None
sqlalchemy            : None
tables                : None
tabulate              : None
xarray                : 2024.7.0
xlrd                  : None
xlsxwriter            : None
zstandard             : None
tzdata                : 2024.1
qtpy                  : None
pyqt5                 : None

@a10y a10y added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 18, 2024
@a10y
Copy link
Author

a10y commented Oct 18, 2024

The failure is occurring in the type property accessor on ArrowDtype. I'm not familiar enough with Pandas internals to be sure, but my suspicion is that this if statement should include a check for is_string_view

elif pa.types.is_string(pa_type) or pa.types.is_large_string(pa_type):
return str

@a10y a10y changed the title BUG: BUG: Failures with ArrowDtype(pa.string_view()) Oct 18, 2024
@a10y
Copy link
Author

a10y commented Oct 18, 2024

I don't have permissions to add but this should include the Arrow label

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant