apache / apache/arrow

Table.rename_columns() drops schema metadata

Open
#48,024 1 comment 0 reactions 1 assignee Claimed by @yashwantbezawada View on GitHub
Component: C++ 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.

Example test case to reproduce bug:

```py
import pyarrow

my_schema = pyarrow.schema(
[pyarrow.field("n_legs", pyarrow.int64()), pyarrow.field("animals", pyarrow.string())],
metadata={"source": "zoo"}, # We want to preserve this
)

table = pyarrow.Table.from_arrays([[2, 4], ["Flamingo", "Horse"]], schema=my_schema)

assert table.schema.metadata == {b"source": b"zoo"}
new_table = table.rename_columns(["n", "name"])
assert new_table.schema.metadata == {b"source": b"zoo"} # oh no - conservation efforts gone awry!
```
The last assert fails due to `metadata` being `None`.

versions tested:
- 21.0.0
- 22.0.0

platforms tested:
- windows

most likely need to copy the metadata here:
https://github.com/apache/arrow/blob/44f82a402422237adc32551a26ea20ab45366282/cpp/src/arrow/table.cc#L369

### Component(s)

Python, C++

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.