-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Python] Use ExtensionScalar.as_py() as fallback in ExtensionArray to_pandas? #33134
Comments
Joris Van den Bossche / @jorisvandenbossche: from collections import namedtuple
import pyarrow as pa
Point3D = namedtuple("Point3D", ["x", "y", "z"])
class Point3DScalar(pa.ExtensionScalar):
def as_py(self) -> Point3D:
return Point3D(*self.value.as_py())
class Point3DType(pa.PyExtensionType):
def __init__(self):
pa.PyExtensionType.__init__(self, pa.list_(pa.float32(), 3))
def __reduce__(self):
return Point3DType, ()
def __arrow_ext_scalar_class__(self):
return Point3DScalar storage = pa.array([[1, 2, 3], [4, 5, 6]], pa.list_(pa.float32(), 3))
arr = pa.ExtensionArray.from_storage(Point3DType(), storage)
>>> arr.to_pandas().values
array([array([1., 2., 3.], dtype=float32),
array([4., 5., 6.], dtype=float32)], dtype=object)
>>> arr.to_pylist()
[Point3D(x=1.0, y=2.0, z=3.0), Point3D(x=4.0, y=5.0, z=6.0)] So here, We could do this automatically in On the other hand, you can also do this yourself by overriding And what about |
Rok Mihevc / @rok: |
Joris Van den Bossche / @jorisvandenbossche: |
Rok Mihevc / @rok: |
Chang She / @changhiskhan: so we have:
|
This was raised in ARROW-17813 by @changhiskhan:
and I also mentioned this in ARROW-17535:
Reporter: Joris Van den Bossche / @jorisvandenbossche
Watchers: Rok Mihevc / @rok
Related issues:
Note: This issue was originally created as ARROW-17925. Please see the migration documentation for further details.
The text was updated successfully, but these errors were encountered: