Skip to content

[Python] Allow creating ExtensionArray through pa.array(..) constructor #33054

Description

@asfimport

Currently, creating an ExtensionArray from a python sequence (or numpy array, ..) requires the following:

frompyarrow.tests.test_extension_typeimportIntegerTypestorage_array=pa.array([1, 2, 3])
ext_arr=pa.ExtensionArray.from_storage(IntegerType(), storage_array)

While doing this directly in pa.array(..) doesn't work:

>>>pa.array([1, 2, 3], type=IntegerType())
ArrowNotImplementedError: extension

I think it should be possible to basically to the ExtensionArray.from_storage under the hood in pa.array(..) when the specified type is an extension type?

I think this should also enable converting from a pandas DataFrame (with a column with matching storage values) to a Table with a specified schema that includes an extension type. Like:

df = pd.DataFrame({'a': [1, 2, 3]})
pa.table(df, schema=pa.schema([('a', IntegerType())]))

Reporter: Joris Van den Bossche / @jorisvandenbossche
Assignee: Joris Van den Bossche / @jorisvandenbossche

Related issues:

Note: This issue was originally created as ARROW-17834. Please see the migration documentation for further details.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions