Skip to content

Commit 811610d

Browse files
authored
BUG: DataFrame repr with ArrowDtype with extension (#54130)
* BUG: DataFrame repr with ArrowDtype with extension * add comment
1 parent 8e403e4 commit 811610d

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

doc/source/whatsnew/v2.1.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ ExtensionArray
598598
- Bug in :meth:`Series.quantile` for pyarrow temporal types raising ArrowInvalid (:issue:`52678`)
599599
- Bug in :meth:`Series.rank` returning wrong order for small values with ``Float64`` dtype (:issue:`52471`)
600600
- Bug in :meth:`~arrays.ArrowExtensionArray.__iter__` and :meth:`~arrays.ArrowExtensionArray.__getitem__` returning python datetime and timedelta objects for non-nano dtypes (:issue:`53326`)
601+
- Bug where the :class:`DataFrame` repr would not work when a column would have an :class:`ArrowDtype` with an ``pyarrow.ExtensionDtype`` (:issue:`54063`)
601602
- Bug where the ``__from_arrow__`` method of masked ExtensionDtypes(e.g. :class:`Float64Dtype`, :class:`BooleanDtype`) would not accept pyarrow arrays of type ``pyarrow.null()`` (:issue:`52223`)
602603

603604
Styler

pandas/core/dtypes/dtypes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,8 +2102,9 @@ def type(self):
21022102
elif pa.types.is_null(pa_type):
21032103
# TODO: None? pd.NA? pa.null?
21042104
return type(pa_type)
2105-
else:
2106-
raise NotImplementedError(pa_type)
2105+
elif isinstance(pa_type, pa.ExtensionType):
2106+
return type(self)(pa_type.storage_type).type
2107+
raise NotImplementedError(pa_type)
21072108

21082109
@property
21092110
def name(self) -> str: # type: ignore[override]

pandas/tests/extension/test_arrow.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
pa = pytest.importorskip("pyarrow", minversion="7.0.0")
6262

6363
from pandas.core.arrays.arrow.array import ArrowExtensionArray
64+
from pandas.core.arrays.arrow.extension_types import ArrowPeriodType
6465

6566

6667
@pytest.fixture(params=tm.ALL_PYARROW_DTYPES, ids=str)
@@ -3143,3 +3144,17 @@ def test_to_numpy_temporal(pa_type):
31433144
expected = np.array(expected, dtype=object)
31443145
assert result[0].unit == expected[0].unit
31453146
tm.assert_numpy_array_equal(result, expected)
3147+
3148+
3149+
def test_arrowextensiondtype_dataframe_repr():
3150+
# GH 54062
3151+
df = pd.DataFrame(
3152+
pd.period_range("2012", periods=3),
3153+
columns=["col"],
3154+
dtype=ArrowDtype(ArrowPeriodType("D")),
3155+
)
3156+
result = repr(df)
3157+
# TODO: repr value may not be expected; address how
3158+
# pyarrow.ExtensionType values are displayed
3159+
expected = " col\n0 15340\n1 15341\n2 15342"
3160+
assert result == expected

0 commit comments

Comments
 (0)