diff --git a/pandas/core/arrays/string_.py b/pandas/core/arrays/string_.py index 7227ea77ca433..ac758d0ef093c 100644 --- a/pandas/core/arrays/string_.py +++ b/pandas/core/arrays/string_.py @@ -123,10 +123,10 @@ class StringDtype(StorageExtensionDtype): Examples -------- >>> pd.StringDtype() - string[python] + )> >>> pd.StringDtype(storage="pyarrow") - string[pyarrow] + )> """ @property @@ -198,11 +198,8 @@ def __init__( self._na_value = na_value def __repr__(self) -> str: - if self._na_value is libmissing.NA: - return f"{self.name}[{self.storage}]" - else: - # TODO add more informative repr - return self.name + storage = "" if self.storage == "pyarrow" else "storage='python', " + return f"" def __eq__(self, other: object) -> bool: # we need to override the base class __eq__ because na_value (NA or NaN) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 0c3f535df9ce2..260fae663a4de 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6809,12 +6809,12 @@ def convert_dtypes( 2 3 z 20 200.0 >>> dfn.dtypes - a Int32 - b string[python] - c boolean - d string[python] - e Int64 - f Float64 + a Int32 + b string + c boolean + d string + e Int64 + f Float64 dtype: object Start with a Series of strings and missing data represented by ``np.nan``. diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index b7fbc4e5e22b7..36bfc261e75c1 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -67,7 +67,6 @@ ExtensionArray, TimedeltaArray, ) -from pandas.core.arrays.string_ import StringDtype from pandas.core.base import PandasObject import pandas.core.common as com from pandas.core.indexes.api import ( @@ -1218,8 +1217,6 @@ def _format(x): return self.na_rep elif isinstance(x, PandasObject): return str(x) - elif isinstance(x, StringDtype): - return repr(x) else: # object dtype return str(formatter(x)) diff --git a/pandas/tests/arrays/string_/test_string.py b/pandas/tests/arrays/string_/test_string.py index 336a0fef69170..5670fad7e2f4f 100644 --- a/pandas/tests/arrays/string_/test_string.py +++ b/pandas/tests/arrays/string_/test_string.py @@ -103,6 +103,18 @@ def test_repr(dtype): assert repr(df.A.array) == expected +def test_dtype_repr(dtype): + if dtype.storage == "pyarrow": + if dtype.na_value is pd.NA: + assert repr(dtype) == ")>" + else: + assert repr(dtype) == "" + elif dtype.na_value is pd.NA: + assert repr(dtype) == ")>" + else: + assert repr(dtype) == "" + + def test_none_to_nan(cls, dtype): a = cls._from_sequence(["a", None, "b"], dtype=dtype) assert a[1] is not None diff --git a/pandas/tests/io/formats/test_to_string.py b/pandas/tests/io/formats/test_to_string.py index 63c975fd831e7..0866581535c2f 100644 --- a/pandas/tests/io/formats/test_to_string.py +++ b/pandas/tests/io/formats/test_to_string.py @@ -777,9 +777,9 @@ def test_to_string_string_dtype(self): result = df.dtypes.to_string() expected = dedent( """\ - x string[pyarrow] - y string[python] - z int64[pyarrow]""" + x string + y string + z int64[pyarrow]""" ) assert result == expected