apache / apache/arrow

[Python] Arrow TypeInferrer fails on maps with non-string or binary keys

Open
#47,023 2 comments 0 reactions 0 assignees View on GitHub
Component: Python Type: bug
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 13h
Merged PRs (30d)
88

Description

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

Currently, `TypeInferrer` fails with the following exception when you're trying to use keys with non-string/binary types:

```
arrow_table = pa.Table.from_pandas(self._table, preserve_index=False)
File "pyarrow/table.pxi", line 4751, in pyarrow.lib.Table.from_pandas
File "/opt/anaconda3/envs/rayturbo/lib/python3.9/site-packages/pyarrow/pandas_compat.py", line 639, in dataframe_to_arrays
arrays = [convert_column(c, f)
File "/opt/anaconda3/envs/rayturbo/lib/python3.9/site-packages/pyarrow/pandas_compat.py", line 639, in
arrays = [convert_column(c, f)
File "/opt/anaconda3/envs/rayturbo/lib/python3.9/site-packages/pyarrow/pandas_compat.py", line 626, in convert_column
raise e
File "/opt/anaconda3/envs/rayturbo/lib/python3.9/site-packages/pyarrow/pandas_compat.py", line 620, in convert_column
result = pa.array(col, type=type_, from_pandas=True, safe=safe)
File "pyarrow/array.pxi", line 362, in pyarrow.lib.array
File "pyarrow/array.pxi", line 87, in pyarrow.lib._ndarray_to_array
File "pyarrow/error.pxi", line 92, in pyarrow.lib.check_status
pyarrow.lib.ArrowTypeError: ("Expected dict key of type str or bytes, got 'int'", 'Conversion failed for column value_counter(value) with type object')
```

However Arrow supports integer type as key-types in the maps perfectly fine:

```
# Fails
arr = pa.array([{0: 1}])

# Works perfectly fine
arr = pa.array([{0: 1}], type=pa.map_(pa.int64(), pa.int64()))
```

### Component(s)

Format

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.