Skip to content

CLN: remove construct_from_string from various #31353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions pandas/tests/extension/arrow/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
import copy
import itertools
from typing import Type

import numpy as np
import pyarrow as pa
Expand All @@ -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.

Expand All @@ -46,7 +40,8 @@ def construct_array_type(cls):
"""
return ArrowBoolArray

def _is_boolean(self):
@property
def _is_boolean(self) -> bool:
return True


Expand All @@ -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.

Expand Down
12 changes: 3 additions & 9 deletions pandas/tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numbers
import random
import sys
from typing import Type

import numpy as np

Expand All @@ -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.

Expand All @@ -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


Expand Down
10 changes: 2 additions & 8 deletions pandas/tests/extension/json/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import random
import string
import sys
from typing import Type

import numpy as np

Expand All @@ -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.

Expand All @@ -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()
Expand Down
10 changes: 2 additions & 8 deletions pandas/tests/extension/list/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numbers
import random
import string
from typing import Type

import numpy as np

Expand All @@ -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.

Expand All @@ -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()
Expand Down