Skip to content

[Python] List array conversion to Numpy N-d array #29892

Description

@asfimport

When converting a single-dimensional array to numpy, the dtype is preserved

importpyarrowaspax = pa.array([.234,.345,.456])
x.to_numpy().dtype # dtype('float64')

But when doing the same for a multi-dimensional array, the dtype is lost and cannot be set manually

x = pa.array([[1,2,3],[4,5,6]]).to_numpy(zero_copy_only=False)
print(x.dtpye) # objectx.astype(np.float64) # ValueError: settinganarrayelementwithasequence.

Which is to say that numpy believes this array is not uniform. The only way to get it to the proper dtype is to convert it to a python list then back to a numpy array.

Is there another way to achieve this? Or, at least, can it be fixed such that we can manually set the dtype of the numpy array after conversion?

I know that pyarrow doesn't support ndarrays with ndim>1 (https://issues.apache.org/jira/browse/ARROW-5645) but I was curious if this can be achieved going the other way.

Reporter: Ben Epstein

Note: This issue was originally created as ARROW-14320. 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

Assignees

No one assigned

    Labels

    Component: PythonStatus: stale-warningIssues and PRs flagged as stale which are due to be closed if no indication otherwiseType: usageIssue is a user question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions