Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] 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
Comment From: jbrockmendel
This inconsistency causes issues for unboxing the values for Bodo JIT
Can you elaborate on this?
Comment From: datapythonista
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.
Comment From: ehsantn
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.
Comment From: ehsantn
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.