Skip to content

[Python] Support converting list of multi-dimensional arrays to FixedShapeTensor #49644

Description

@jorisvandenbossche

Describe the enhancement requested

When you want to construct a fixed shape tensor array, not from a single contiguous ndarray, but from a list of the individual array elements, this "accidentally" works for 1d arrays (because we support that for ListArray):

>>>pa.array([np.array([1,2,3]), np.array([2,3,4])], type=pa.fixed_shape_tensor(pa.int64(), shape=(3,)))
<pyarrow.lib.FixedShapeTensorArrayobjectat0x7fadc4d1f3a0>
[
[
1,
2,
3
],
[
2,
3,
4
]
]

But trying the same for >1 d arrays, you get the following error:

>>>pa.array([np.array([[1,2,3]]), np.array([[2,3,4]])], type=pa.fixed_shape_tensor(pa.int64(), shape=(1, 3)))
...
ArrowInvalid: Canonlyconvert1-dimensionalarrayvalues

AFAIK, the only way to currently do this conversion, is to convert the list of arrays to a single ndarray yourself, and then use pa.FixedShapeTensorArray.from_numpy_ndarray.

(cc @rok)

Component(s)

Python

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