Skip to content

Commit 0a099d8

Browse files
simonjayhawkinsjreback
authored andcommitted
CLN: remove construct_from_string from various (#31353)
1 parent 9bef78d commit 0a099d8

File tree

4 files changed

+12
-42
lines changed

4 files changed

+12
-42
lines changed

pandas/tests/extension/arrow/arrays.py

+5-17
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88
import copy
99
import itertools
10+
from typing import Type
1011

1112
import numpy as np
1213
import pyarrow as pa
@@ -29,14 +30,7 @@ class ArrowBoolDtype(ExtensionDtype):
2930
na_value = pa.NULL
3031

3132
@classmethod
32-
def construct_from_string(cls, string):
33-
if string == cls.name:
34-
return cls()
35-
else:
36-
raise TypeError(f"Cannot construct a '{cls.__name__}' from '{string}'")
37-
38-
@classmethod
39-
def construct_array_type(cls):
33+
def construct_array_type(cls) -> Type["ArrowBoolArray"]:
4034
"""
4135
Return the array type associated with this dtype.
4236
@@ -46,7 +40,8 @@ def construct_array_type(cls):
4640
"""
4741
return ArrowBoolArray
4842

49-
def _is_boolean(self):
43+
@property
44+
def _is_boolean(self) -> bool:
5045
return True
5146

5247

@@ -59,14 +54,7 @@ class ArrowStringDtype(ExtensionDtype):
5954
na_value = pa.NULL
6055

6156
@classmethod
62-
def construct_from_string(cls, string):
63-
if string == cls.name:
64-
return cls()
65-
else:
66-
raise TypeError(f"Cannot construct a '{cls}' from '{string}'")
67-
68-
@classmethod
69-
def construct_array_type(cls):
57+
def construct_array_type(cls) -> Type["ArrowStringArray"]:
7058
"""
7159
Return the array type associated with this dtype.
7260

pandas/tests/extension/decimal/array.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import numbers
33
import random
44
import sys
5+
from typing import Type
56

67
import numpy as np
78

@@ -26,7 +27,7 @@ def __repr__(self) -> str:
2627
return f"DecimalDtype(context={self.context})"
2728

2829
@classmethod
29-
def construct_array_type(cls):
30+
def construct_array_type(cls) -> Type["DecimalArray"]:
3031
"""
3132
Return the array type associated with this dtype.
3233
@@ -36,15 +37,8 @@ def construct_array_type(cls):
3637
"""
3738
return DecimalArray
3839

39-
@classmethod
40-
def construct_from_string(cls, string):
41-
if string == cls.name:
42-
return cls()
43-
else:
44-
raise TypeError(f"Cannot construct a '{cls.__name__}' from '{string}'")
45-
4640
@property
47-
def _is_numeric(self):
41+
def _is_numeric(self) -> bool:
4842
return True
4943

5044

pandas/tests/extension/json/array.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import random
1717
import string
1818
import sys
19+
from typing import Type
1920

2021
import numpy as np
2122

@@ -29,7 +30,7 @@ class JSONDtype(ExtensionDtype):
2930
na_value = UserDict()
3031

3132
@classmethod
32-
def construct_array_type(cls):
33+
def construct_array_type(cls) -> Type["JSONArray"]:
3334
"""
3435
Return the array type associated with this dtype.
3536
@@ -39,13 +40,6 @@ def construct_array_type(cls):
3940
"""
4041
return JSONArray
4142

42-
@classmethod
43-
def construct_from_string(cls, string):
44-
if string == cls.name:
45-
return cls()
46-
else:
47-
raise TypeError(f"Cannot construct a '{cls.__name__}' from '{string}'")
48-
4943

5044
class JSONArray(ExtensionArray):
5145
dtype = JSONDtype()

pandas/tests/extension/list/array.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numbers
77
import random
88
import string
9+
from typing import Type
910

1011
import numpy as np
1112

@@ -21,7 +22,7 @@ class ListDtype(ExtensionDtype):
2122
na_value = np.nan
2223

2324
@classmethod
24-
def construct_array_type(cls):
25+
def construct_array_type(cls) -> Type["ListArray"]:
2526
"""
2627
Return the array type associated with this dtype.
2728
@@ -31,13 +32,6 @@ def construct_array_type(cls):
3132
"""
3233
return ListArray
3334

34-
@classmethod
35-
def construct_from_string(cls, string):
36-
if string == cls.name:
37-
return cls()
38-
else:
39-
raise TypeError(f"Cannot construct a '{cls}' from '{string}'")
40-
4135

4236
class ListArray(ExtensionArray):
4337
dtype = ListDtype()

0 commit comments

Comments
 (0)