Skip to content

[Python] FixedShapeTensorArray.to_numpy_ndarray() fails with numpy arrays of type string in Pyarrow-16, but works with v15 #43614

Description

@bschindler

Describe the bug, including details regarding any error messages, version, and platform.

FixedShapeTensorArray.to_numpy_ndarray() fails with numpy arrays of type string

with pyarrow 16, whereas pyarrow 15 works. As a result, we are unable to load our feather files that were created with older pyarrow versions.
While we should not have stored those strings this way, we have now a significant library of files that contain such constructs.
Code to load the file:

from pathlib import Path
from typing import Any
import pyarrow as pa
def _extract_element_feather(column: Any):
import pyarrow as pa
if type(column) == pa.lib.FixedShapeTensorArray:
return column.to_numpy_ndarray()
else:
return column.as_py()
with pa.ipc.open_file(Path("out.feather")) as reader:
table = reader.get_batch(0)
features = {
k.name: _extract_element_feather(table[k.name])
for k in table.schema
}
print(features)

Test file: out.feather.zip

Pyarrow 16:

 File "/Users/bschindler/Library/Application Support/JetBrains/PyCharm2024.1/scratches/scratch_41.py", line 17, in <module>
features = {
File "/Users/bschindler/Library/Application Support/JetBrains/PyCharm2024.1/scratches/scratch_41.py", line 18, in <dictcomp>
k.name: _extract_element_feather(table[k.na
me])
File "/Users/bschindler/Library/Application Support/JetBrains/PyCharm2024.1/scratches/scratch_41.py", line 11, in _extract_element_feather
return column.to_numpy_ndarray()
File "pyarrow/array.pxi", line 4240, in pyarrow.lib.FixedShapeTensorArray.to_numpy_ndarray
File "pyarrow/array.pxi", line 4265, in pyarrow.lib.FixedShapeTensorArray.to_tensor
File "pyarrow/error.pxi", line 154, in pyarrow.lib.pyarrow_internal_check_status
File "pyarrow/error.pxi", line 91, in pyarrow.lib.check_status
pyarrow.lib.ArrowTypeError: string is not valid data type for a tensor

Pyarrow 15:

 {'data': array([['Hello World']], dtype=object)}

Component(s)

Python

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions