diff --git a/python/pyarrow/pandas_compat.py b/python/pyarrow/pandas_compat.py index 689cbca6b7165..9fa7a699efbae 100644 --- a/python/pyarrow/pandas_compat.py +++ b/python/pyarrow/pandas_compat.py @@ -541,7 +541,9 @@ def dataframe_to_types(df, preserve_index, columns=None): if _pandas_api.is_categorical(values): type_ = pa.array(c, from_pandas=True).type elif _pandas_api.is_extension_array_dtype(values): - type_ = pa.array(c.head(0), from_pandas=True).type + empty = c.head(0) if isinstance( + c, _pandas_api.pd.Series) else c[:0] + type_ = pa.array(empty, from_pandas=True).type else: values, type_ = get_datetimetz_type(values, c.dtype, None) type_ = pa.lib._ndarray_to_arrow_type(values, type_) diff --git a/python/pyarrow/tests/test_schema.py b/python/pyarrow/tests/test_schema.py index f26eaaf5fc14f..0547d850d3602 100644 --- a/python/pyarrow/tests/test_schema.py +++ b/python/pyarrow/tests/test_schema.py @@ -663,7 +663,7 @@ def test_schema_from_pandas(): if Version(pd.__version__) >= Version('1.0.0'): inputs.append(pd.array([1, 2, None], dtype=pd.Int32Dtype())) for data in inputs: - df = pd.DataFrame({'a': data}) + df = pd.DataFrame({'a': data}, index=data) schema = pa.Schema.from_pandas(df) expected = pa.Table.from_pandas(df).schema assert schema == expected