BUG: StringArray is a subclass of PandasArray

This issue has been created since 2022-09-19.

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

In [2]: A = pd.array(["a1", "a2"], dtype="string")

In [3]: A
Out[3]:
<StringArray>
['a1', 'a2']
Length: 2, dtype: string

In [4]: isinstance(A, pd.arrays.StringArray)
Out[4]: True

In [5]: isinstance(A, pd.arrays.PandasArray)
Out[5]: True

Issue Description

PandasArray is described as a thin wrapper around Numpy values for internal compatibility. However, StringArray is a subclass of PandasArray for some reason (other ExtensionArrays are not). This inconsistency causes issues for unboxing the values for Bodo JIT (and I assume other systems consuming Pandas data).

https://pandas.pydata.org/docs/reference/api/pandas.Series.array.html
https://pandas.pydata.org/docs/reference/api/pandas.arrays.PandasArray.html

Expected Behavior

Output of isinstance(pd.array(["a1", "a2"], dtype="string"), pd.arrays.PandasArray) should be False.

Installed Versions

INSTALLED VERSIONS ------------------ commit : bf856a8 python : 3.9.6.final.0 python-bits : 64 OS : Darwin OS-release : 21.2.0 Version : Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64 machine : x86_64 processor : i386 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 1.6.0.dev0+145.gbf856a85a3
numpy : 1.21.1
pytz : 2021.1
dateutil : 2.8.2
setuptools : 49.6.0.post20210108
pip : 21.2.2
Cython : 0.29.32
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.26.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli :
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
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

jbrockmendel wrote this answer on 2022-09-21

This inconsistency causes issues for unboxing the values for Bodo JIT

Can you elaborate on this?

datapythonista wrote this answer on 2022-09-21

Thanks for the report. I don't think the API for extension arrays is very clear. Did you try to simply remove the subclass here and see what fails? I guess there may be some generic functionality that lives in the parent classes meant for numpy backed data. It'd surely make sense to move things to the right place if that's the case.

ehsantn wrote this answer on 2022-09-21

This inconsistency causes issues for unboxing the values for Bodo JIT

Can you elaborate on this?

The code paths for unboxing each array type is different. For PandasArray, Bodo just needs to unbox _ndarray since PandasArray is just a wrapper for Numpy arrays. StringArray is a different code path with slight differences such as handling pd.NA. This led to an error in Bodo so I noticed this class hierarchy issue.

ehsantn wrote this answer on 2022-09-21

Thanks for the report. I don't think the API for extension arrays is very clear. Did you try to simply remove the subclass here and see what fails? I guess there may be some generic functionality that lives in the parent classes meant for numpy backed data. It'd surely make sense to move things to the right place if that's the case.

Yes, the APIs should be clarified to enable more robust integration with Pandas in general. Removing the subclass causes an error somewhere else so it may be a bit of work. Not a big issue for us right now since the workaround is just an extra type check. Opened the issue as feedback about extension array APIs and what other users may expect.

More Details About Repo
Owner Name pandas-dev
Repo Name pandas
Full Name pandas-dev/pandas
Language Python
Created Date 2010-08-24
Updated Date 2022-09-29
Star Count 35374
Watcher Count 1122
Fork Count 15034
Issue Count 3579

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Python code isn't evaluated, only code *itself* showing in browser + Bizarre Syntax Errors 1 2022-08-20 2022-09-18
Can't select more than 4 images and/or 1 video. 0 2021-02-02 2022-09-22
Possible to recognize whatever TOC convention appears in the document 2 2021-09-24 2022-07-18
Error: y contains previously unseen labels: [4] 2 2021-12-22 2022-09-17
Add more ways of sending color via OSC 1 2021-12-24 2022-09-08
R version compatibility 1 2021-10-07 2022-09-16
power flow not converging 10 2021-05-09 2022-08-22
File Download complete but file has 0 bytes 9 2020-08-12 2022-07-23
`valuePublisher` does not publish when an `Object`'s `LinkingObjects` is updated. 6 2021-12-26 2022-09-08
jupyter-book watch command 5 2021-09-08 2022-09-23
ui files not found 1 2021-06-30 2021-12-30
Install older versions of R 4 2015-09-10 2022-09-17
Merging a branch that has merge commits 1 2021-05-26 2022-09-21
Getting latestMessage sender name 5 2015-10-01 2022-09-02
labels dont show in jupyter lab 2 2021-12-06 2022-09-18
BTT SKR E3 Turbo -> creating Ender-5-Pro Firmware with BLTouch not working 2 2021-03-18 2022-09-22
Heaters turn off and motors stay on and get HOT 4 2021-06-24 2022-09-22
minibatch generation 2 2022-01-03 2022-09-26
Font size style example in cheatsheet uses quirky lengths and doesn’t work in Firefox 5 2022-04-05 2022-09-17
Things like `fmt.println()` escape sandbox 5 2021-08-20 2022-09-29
[BUG] Cannot migrate VMs after shutdown nodes 1 2022-04-14 2022-09-22
How hidden marker? 1 2021-01-04 2022-01-13
Don't autocomplete `#'` to `#''` for r files 2 2021-12-22 2022-09-02
[plugin-architecture] Add Markdown Renderer on Comments 0 2022-04-06 2022-07-01
[plugin-architecture] Use variables on breakpoints 3 2022-04-22 2022-07-01
[plugin-architecture] Handle comments error messages 0 2022-04-28 2022-07-01
Please attach sources to the release 0 2021-08-30 2022-09-16
Template glitch 0 2021-10-10 2022-01-20
updated to new version and it wont load on Win 11 Pro Version 10.0.22000 Build 22000 0 2021-12-18 2022-09-12
Minor grammatical changes / suggestions 6 2022-04-04 2022-08-11
CAS Auto Begin Firemission not working 1 2021-12-17 2022-09-15
`git_changelog` cannot be used from outside 0 2021-10-15 2022-09-24
Cstring breaks old workflows 5 2021-01-04 2022-09-08
http.headers.User-Agent - <PUT TITLE HERE> 1 2021-11-12 2022-09-15
Add support for multi-resolution data 0 2021-09-24 2022-09-15
[Python] match and case not highlighted until terminating colon is entered 7 2021-10-10 2022-08-27
Fido2 Webauthn broken on latest version of Android app (2.13.0) 3 2021-09-26 2022-09-25
Issue with ACF 5.11 (new version) - Can't access get_field from wordpress admin 7 2021-11-11 2022-07-17
Consider adding AXE xpath and AXE "Message" field 1 2020-05-18 2022-08-23
Inappropriate CAPPEDWORD conversion from PascalCase to snake_case 0 2022-04-27 2022-09-28
libssh has deprecated lots of function calls 0 2022-08-29 2022-09-28
https://catalog-stage-datagov.app.cloud.gov/user/saml2login not working 1 2022-01-13 2022-07-17
ZERO support for building cloudformation resources and incomplete documentation 3 2021-10-25 2022-09-13
User can create a managed private nodegroups in a private IPv6 cluster 2 2021-10-01 2022-01-16
Installation error using pip 2 2022-02-05 2022-09-01
How can I recover from the ""Duplicate mapping key" expectation"? 0 2021-12-16 2022-09-27
LWG-3598 `system_category().default_error_condition(0)` is underspecified 1 2022-02-08 2022-09-10
"Stripe\Exception\InvalidRequestException: Invalid integer: in file ..." swapping a subscription item with metered price 1 2022-02-22 2022-08-28
IP is not set on Ingress when using Multiple nginx Ingress controller in the same namespace 16 2022-02-02 2022-09-27
Test failure GC\\Coverage\\LargeObjectAlloc2\\LargeObjectAlloc2.cmd 3 2022-03-14 2022-09-27