File tree Expand file tree Collapse file tree 5 files changed +21
-16
lines changed Expand file tree Collapse file tree 5 files changed +21
-16
lines changed Original file line number Diff line number Diff line change @@ -119,10 +119,10 @@ class StringDtype(StorageExtensionDtype):
119
119
Examples
120
120
--------
121
121
>>> pd.StringDtype()
122
- <StringDtype(storage=' python', na_value=<NA>)>
122
+ string[ python]
123
123
124
124
>>> pd.StringDtype(storage="pyarrow")
125
- <StringDtype(na_value=<NA>)>
125
+ string[pyarrow]
126
126
"""
127
127
128
128
@property
@@ -194,8 +194,11 @@ def __init__(
194
194
self ._na_value = na_value
195
195
196
196
def __repr__ (self ) -> str :
197
- storage = "" if self .storage == "pyarrow" else "storage='python', "
198
- return f"<StringDtype({ storage } na_value={ self ._na_value } )>"
197
+ if self ._na_value is libmissing .NA :
198
+ return f"{ self .name } [{ self .storage } ]"
199
+ else :
200
+ storage = "" if self .storage == "pyarrow" else "storage='python', "
201
+ return f"<StringDtype({ storage } na_value={ self ._na_value } )>"
199
202
200
203
def __eq__ (self , other : object ) -> bool :
201
204
# we need to override the base class __eq__ because na_value (NA or NaN)
Original file line number Diff line number Diff line change @@ -7021,13 +7021,12 @@ def convert_dtypes(
7021
7021
2 3 z <NA> <NA> 20 200.0
7022
7022
7023
7023
>>> dfn.dtypes
7024
- a Int32
7025
- b string
7026
- c boolean
7027
- d string
7028
- e Int64
7029
- f Float64
7030
- dtype: object
7024
+ a Int32
7025
+ b string[python]
7026
+ c boolean
7027
+ d string[python]
7028
+ e Int64
7029
+ f Float64
7031
7030
7032
7031
Start with a Series of strings and missing data represented by ``np.nan``.
7033
7032
Original file line number Diff line number Diff line change 66
66
ExtensionArray ,
67
67
TimedeltaArray ,
68
68
)
69
+ from pandas .core .arrays .string_ import StringDtype
69
70
from pandas .core .base import PandasObject
70
71
import pandas .core .common as com
71
72
from pandas .core .indexes .api import (
@@ -1231,6 +1232,8 @@ def _format(x):
1231
1232
return self .na_rep
1232
1233
elif isinstance (x , PandasObject ):
1233
1234
return str (x )
1235
+ elif isinstance (x , StringDtype ) and x .na_value is NA :
1236
+ return repr (x )
1234
1237
else :
1235
1238
# object dtype
1236
1239
return str (formatter (x ))
Original file line number Diff line number Diff line change @@ -126,11 +126,11 @@ def test_repr(dtype):
126
126
def test_dtype_repr (dtype ):
127
127
if dtype .storage == "pyarrow" :
128
128
if dtype .na_value is pd .NA :
129
- assert repr (dtype ) == "<StringDtype(na_value=<NA>)> "
129
+ assert repr (dtype ) == "string[pyarrow] "
130
130
else :
131
131
assert repr (dtype ) == "<StringDtype(na_value=nan)>"
132
132
elif dtype .na_value is pd .NA :
133
- assert repr (dtype ) == "<StringDtype(storage=' python', na_value=<NA>)> "
133
+ assert repr (dtype ) == "string[ python] "
134
134
else :
135
135
assert repr (dtype ) == "<StringDtype(storage='python', na_value=nan)>"
136
136
Original file line number Diff line number Diff line change @@ -758,9 +758,9 @@ def test_to_string_string_dtype(self):
758
758
result = df .dtypes .to_string ()
759
759
expected = dedent (
760
760
"""\
761
- x string
762
- y string
763
- z int64[pyarrow]"""
761
+ x string[pyarrow]
762
+ y string[python]
763
+ z int64[pyarrow]"""
764
764
)
765
765
assert result == expected
766
766
You can’t perform that action at this time.
0 commit comments