diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 99e4cb0545e2d..0f5ea54d1d410 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -447,7 +447,10 @@ def __init__( if isinstance(values.dtype, ArrowDtype) and issubclass( values.dtype.type, CategoricalDtypeType ): - arr = values._pa_array.combine_chunks() + if values.__class__.__name__ == 'Index': + arr = values._data._pa_array.combine_chunks() + else: + arr = values._pa_array.combine_chunks() categories = arr.dictionary.to_pandas(types_mapper=ArrowDtype) codes = arr.indices.to_numpy() dtype = CategoricalDtype(categories, values.dtype.pyarrow_dtype.ordered) diff --git a/pandas/tests/arrays/categorical/test_dtypes.py b/pandas/tests/arrays/categorical/test_dtypes.py index ec1d501ddba16..22e58c9b08a05 100644 --- a/pandas/tests/arrays/categorical/test_dtypes.py +++ b/pandas/tests/arrays/categorical/test_dtypes.py @@ -1,7 +1,11 @@ import numpy as np +import pyarrow as pa import pytest -from pandas.core.dtypes.dtypes import CategoricalDtype +from pandas.core.dtypes.dtypes import ( + ArrowDtype, + CategoricalDtype, +) from pandas import ( Categorical, @@ -136,3 +140,17 @@ def test_interval_index_category(self): [0, 1], [1, 2], dtype="interval[uint64, right]" ) tm.assert_index_equal(result, expected) + + def test_values_is_index(): + # GH 60563 + values = Index(["a1", "a2"], dtype=ArrowDtype(pa.string())) + arr = values._data._pa_array.combine_chunks() + + assert arr.equals(values._data._pa_array.combine_chunks()) + + def test_values_is_not_index(): + # GH 60563 + values = Series(["a1", "a2"], dtype=ArrowDtype(pa.string())) + arr = values._pa_array.combine_chunks() + + assert arr.equals(values._pa_array.combine_chunks())