Skip to content

Commit e2ac52d

Browse files
Piong1997pitrou
andauthored
GH-44188: [Python] Fix pandas roundtrip with bytes column names (#44171)
### Rationale for this change There is a bug that when column dtype is np.bytes,it will goto the final branch and run level=level.astype(dtype) ### Are these changes tested? Yes * GitHub Issue: #44188 Lead-authored-by: Piong1997 <[email protected]> Co-authored-by: Antoine Pitrou <[email protected]> Signed-off-by: Antoine Pitrou <[email protected]>
1 parent d87bc99 commit e2ac52d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

python/pyarrow/pandas_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ def _reconstruct_columns_from_metadata(columns, column_indexes):
11631163
if dtype == np.bytes_:
11641164
level = level.map(encoder)
11651165
# ARROW-13756: if index is timezone aware DataTimeIndex
1166-
if pandas_dtype == "datetimetz":
1166+
elif pandas_dtype == "datetimetz":
11671167
tz = pa.lib.string_to_tzinfo(
11681168
column_indexes[0]['metadata']['timezone'])
11691169
level = pd.to_datetime(level, utc=True).tz_convert(tz)

python/pyarrow/tests/test_pandas.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5255,6 +5255,13 @@ def roundtrip(df, schema=None):
52555255
schema=schema)
52565256

52575257

5258+
def test_bytes_column_name_to_pandas():
5259+
df = pd.DataFrame([[0.1, 0.2], [0.3, 0.4]], columns=[b'col1', b'col2'])
5260+
table = pa.Table.from_pandas(df)
5261+
assert table.column_names == ['col1', 'col2']
5262+
assert table.to_pandas().equals(df)
5263+
5264+
52585265
@pytest.mark.processes
52595266
def test_is_data_frame_race_condition():
52605267
# See https://github.com/apache/arrow/issues/39313

0 commit comments

Comments
 (0)