BUG: creating column with ArrowDtype using pyarrow extension type fails on 2.0.3 · Issue #54063 · pandas-dev/pandas (original) (raw)

Creating a pandas DataFrame using ArrowDtype holding a pyarrow array with extension type fails using pandas 2.0.3:

In [1]: ext_arr = pa.array(pd.period_range("2012", periods=3))

In [2]: df = pa.table({'col': ext_arr}).to_pandas(types_mapper=pd.ArrowDtype)
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Cell In[2], line 1
----> 1 df = pa.table({'col': ext_arr}).to_pandas(types_mapper=pd.ArrowDtype)

...

File ~/miniconda3/envs/pandas20/lib/python3.11/site-packages/pandas/core/internals/api.py:73, in make_block(values, placement, klass, ndim, dtype)
     70     placement = BlockPlacement(placement)
     72 ndim = maybe_infer_ndim(values, placement, ndim)
---> 73 if is_datetime64tz_dtype(values.dtype) or is_period_dtype(values.dtype):
     74     # GH#41168 ensure we can pass 1D dt64tz values
     75     # More generally, any EA dtype that isn't is_1d_only_ea_dtype
     76     values = extract_array(values, extract_numpy=True)
     77     values = ensure_block_shape(values, ndim)

File ~/miniconda3/envs/pandas20/lib/python3.11/site-packages/pandas/core/dtypes/common.py:415, in is_period_dtype(arr_or_dtype)
    387 """
    388 Check whether an array-like or dtype is of the Period dtype.
    389 
   (...)
    411 True
    412 """
    413 if isinstance(arr_or_dtype, ExtensionDtype):
    414     # GH#33400 fastpath for dtype object
--> 415     return arr_or_dtype.type is Period
    417 if arr_or_dtype is None:
    418     return False

File ~/miniconda3/envs/pandas20/lib/python3.11/site-packages/pandas/core/arrays/arrow/dtype.py:150, in ArrowDtype.type(self)
    148     return type(pa_type)
    149 else:
--> 150     raise NotImplementedError(pa_type)

NotImplementedError: extension<pandas.period<ArrowPeriodType>>

This works on the main branch, although there are still some other issues such as the repr not working, see #54062