1
1
from __future__ import annotations
2
2
3
- from typing import (
4
- TYPE_CHECKING ,
5
- Any ,
6
- )
3
+ from typing import TYPE_CHECKING
7
4
8
5
import numpy as np
9
6
24
21
25
22
from pandas .core .dtypes .base import (
26
23
ExtensionDtype ,
24
+ StorageExtensionDtype ,
27
25
register_extension_dtype ,
28
26
)
29
27
from pandas .core .dtypes .common import (
55
53
56
54
57
55
@register_extension_dtype
58
- class StringDtype (ExtensionDtype ):
56
+ class StringDtype (StorageExtensionDtype ):
59
57
"""
60
58
Extension dtype for string data.
61
59
@@ -67,7 +65,7 @@ class StringDtype(ExtensionDtype):
67
65
parts of the API may change without warning.
68
66
69
67
In particular, StringDtype.na_value may change to no longer be
70
- ``numpy.nan ``.
68
+ ``pd.NA ``.
71
69
72
70
Parameters
73
71
----------
@@ -141,7 +139,6 @@ def construct_from_string(cls, string):
141
139
-----
142
140
TypeError
143
141
If the string is not a valid option.
144
-
145
142
"""
146
143
if not isinstance (string , str ):
147
144
raise TypeError (
@@ -156,15 +153,6 @@ def construct_from_string(cls, string):
156
153
else :
157
154
raise TypeError (f"Cannot construct a '{ cls .__name__ } ' from '{ string } '" )
158
155
159
- def __eq__ (self , other : Any ) -> bool :
160
- if isinstance (other , str ) and other == "string" :
161
- return True
162
- return super ().__eq__ (other )
163
-
164
- def __hash__ (self ) -> int :
165
- # custom __eq__ so have to override __hash__
166
- return super ().__hash__ ()
167
-
168
156
# https://github.com/pandas-dev/pandas/issues/36126
169
157
# error: Signature of "construct_array_type" incompatible with supertype
170
158
# "ExtensionDtype"
@@ -185,12 +173,6 @@ def construct_array_type( # type: ignore[override]
185
173
else :
186
174
return ArrowStringArray
187
175
188
- def __repr__ (self ):
189
- return f"string[{ self .storage } ]"
190
-
191
- def __str__ (self ):
192
- return self .name
193
-
194
176
def __from_arrow__ (
195
177
self , array : pyarrow .Array | pyarrow .ChunkedArray
196
178
) -> BaseStringArray :
0 commit comments