diff --git a/python/pyarrow/src/arrow/python/arrow_to_pandas.cc b/python/pyarrow/src/arrow/python/arrow_to_pandas.cc index eb60d9d54f85..48dbc950d8f3 100644 --- a/python/pyarrow/src/arrow/python/arrow_to_pandas.cc +++ b/python/pyarrow/src/arrow/python/arrow_to_pandas.cc @@ -2404,9 +2404,11 @@ class ConsolidatedBlockCreator : public PandasBlockCreator { Status CreateBlocks() { for (int i = 0; i < num_columns_; ++i) { - const DataType& type = *arrays_[i]->type(); PandasWriter::type output_type; RETURN_NOT_OK(GetBlockType(i, &output_type)); + // GetBlockType may replace the column (extension storage, decoded + // run-end encoding), so take the type afterwards. + const DataType& type = *arrays_[i]->type(); int block_placement = 0; std::shared_ptr writer; diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py index ca063bc6b695..75bcf4524ed7 100644 --- a/python/pyarrow/tests/test_array.py +++ b/python/pyarrow/tests/test_array.py @@ -4356,6 +4356,16 @@ def test_run_end_encoded_to_pandas(): ree_array.to_pandas(zero_copy_only=True) +@pytest.mark.pandas +def test_run_end_encoded_timestamp_tz_table_to_pandas(): + # GH-55837: the pandas writer must see the decoded type + import pandas as pd + arr = pa.array([0, 0, 3600, None], pa.timestamp('s', tz='Europe/Brussels')) + result = pa.table({'c': pc.run_end_encode(arr)}).to_pandas() + expected = pa.table({'c': arr}).to_pandas() + pd.testing.assert_frame_equal(result, expected) + + @pytest.mark.parametrize(('list_array_type', 'list_type_factory'), [(pa.ListViewArray, pa.list_view), (pa.LargeListViewArray, pa.large_list_view)])