diff --git a/pandas/tests/extension/arrow/arrays.py b/pandas/tests/extension/arrow/arrays.py index b0e5a6f85feeb..b67ca4cfab83d 100644 --- a/pandas/tests/extension/arrow/arrays.py +++ b/pandas/tests/extension/arrow/arrays.py @@ -7,6 +7,7 @@ """ import copy import itertools +from typing import Type import numpy as np import pyarrow as pa @@ -29,14 +30,7 @@ class ArrowBoolDtype(ExtensionDtype): na_value = pa.NULL @classmethod - def construct_from_string(cls, string): - if string == cls.name: - return cls() - else: - raise TypeError(f"Cannot construct a '{cls.__name__}' from '{string}'") - - @classmethod - def construct_array_type(cls): + def construct_array_type(cls) -> Type["ArrowBoolArray"]: """ Return the array type associated with this dtype. @@ -46,7 +40,8 @@ def construct_array_type(cls): """ return ArrowBoolArray - def _is_boolean(self): + @property + def _is_boolean(self) -> bool: return True @@ -59,14 +54,7 @@ class ArrowStringDtype(ExtensionDtype): na_value = pa.NULL @classmethod - def construct_from_string(cls, string): - if string == cls.name: - return cls() - else: - raise TypeError(f"Cannot construct a '{cls}' from '{string}'") - - @classmethod - def construct_array_type(cls): + def construct_array_type(cls) -> Type["ArrowStringArray"]: """ Return the array type associated with this dtype. diff --git a/pandas/tests/extension/decimal/array.py b/pandas/tests/extension/decimal/array.py index 85bd5f7a33fe1..46ab8fe9a62ed 100644 --- a/pandas/tests/extension/decimal/array.py +++ b/pandas/tests/extension/decimal/array.py @@ -2,6 +2,7 @@ import numbers import random import sys +from typing import Type import numpy as np @@ -26,7 +27,7 @@ def __repr__(self) -> str: return f"DecimalDtype(context={self.context})" @classmethod - def construct_array_type(cls): + def construct_array_type(cls) -> Type["DecimalArray"]: """ Return the array type associated with this dtype. @@ -36,15 +37,8 @@ def construct_array_type(cls): """ return DecimalArray - @classmethod - def construct_from_string(cls, string): - if string == cls.name: - return cls() - else: - raise TypeError(f"Cannot construct a '{cls.__name__}' from '{string}'") - @property - def _is_numeric(self): + def _is_numeric(self) -> bool: return True diff --git a/pandas/tests/extension/json/array.py b/pandas/tests/extension/json/array.py index a065c33689c78..dc4653bd01dea 100644 --- a/pandas/tests/extension/json/array.py +++ b/pandas/tests/extension/json/array.py @@ -16,6 +16,7 @@ import random import string import sys +from typing import Type import numpy as np @@ -29,7 +30,7 @@ class JSONDtype(ExtensionDtype): na_value = UserDict() @classmethod - def construct_array_type(cls): + def construct_array_type(cls) -> Type["JSONArray"]: """ Return the array type associated with this dtype. @@ -39,13 +40,6 @@ def construct_array_type(cls): """ return JSONArray - @classmethod - def construct_from_string(cls, string): - if string == cls.name: - return cls() - else: - raise TypeError(f"Cannot construct a '{cls.__name__}' from '{string}'") - class JSONArray(ExtensionArray): dtype = JSONDtype() diff --git a/pandas/tests/extension/list/array.py b/pandas/tests/extension/list/array.py index 6dd00ad3b06ba..7c1da5e8102e2 100644 --- a/pandas/tests/extension/list/array.py +++ b/pandas/tests/extension/list/array.py @@ -6,6 +6,7 @@ import numbers import random import string +from typing import Type import numpy as np @@ -21,7 +22,7 @@ class ListDtype(ExtensionDtype): na_value = np.nan @classmethod - def construct_array_type(cls): + def construct_array_type(cls) -> Type["ListArray"]: """ Return the array type associated with this dtype. @@ -31,13 +32,6 @@ def construct_array_type(cls): """ return ListArray - @classmethod - def construct_from_string(cls, string): - if string == cls.name: - return cls() - else: - raise TypeError(f"Cannot construct a '{cls}' from '{string}'") - class ListArray(ExtensionArray): dtype = ListDtype()