Skip to content

Commit 78217e0

Browse files
TYP: pandas/core/arrays/sparse/dtype.py (#31349)
1 parent 12af3cd commit 78217e0

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pandas/core/arrays/sparse/dtype.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Sparse Dtype"""
22

33
import re
4-
from typing import Any, Tuple
4+
from typing import TYPE_CHECKING, Any, Tuple, Type
55

66
import numpy as np
77

@@ -19,6 +19,9 @@
1919
from pandas.core.dtypes.dtypes import register_extension_dtype
2020
from pandas.core.dtypes.missing import isna, na_value_for_dtype
2121

22+
if TYPE_CHECKING:
23+
from pandas.core.arrays.sparse.array import SparseArray # noqa: F401
24+
2225

2326
@register_extension_dtype
2427
class SparseDtype(ExtensionDtype):
@@ -137,11 +140,11 @@ def _is_na_fill_value(self):
137140
return isna(self.fill_value)
138141

139142
@property
140-
def _is_numeric(self):
143+
def _is_numeric(self) -> bool:
141144
return not is_object_dtype(self.subtype)
142145

143146
@property
144-
def _is_boolean(self):
147+
def _is_boolean(self) -> bool:
145148
return is_bool_dtype(self.subtype)
146149

147150
@property
@@ -167,20 +170,20 @@ def __repr__(self) -> str:
167170
return self.name
168171

169172
@classmethod
170-
def construct_array_type(cls):
173+
def construct_array_type(cls) -> Type["SparseArray"]:
171174
"""
172175
Return the array type associated with this dtype.
173176
174177
Returns
175178
-------
176179
type
177180
"""
178-
from pandas.core.arrays.sparse.array import SparseArray
181+
from pandas.core.arrays.sparse.array import SparseArray # noqa: F811
179182

180183
return SparseArray
181184

182185
@classmethod
183-
def construct_from_string(cls, string):
186+
def construct_from_string(cls, string: str) -> "SparseDtype":
184187
"""
185188
Construct a SparseDtype from a string form.
186189
@@ -266,7 +269,7 @@ def _parse_subtype(dtype: str) -> Tuple[str, bool]:
266269
return subtype, has_fill_value
267270

268271
@classmethod
269-
def is_dtype(cls, dtype):
272+
def is_dtype(cls, dtype: object) -> bool:
270273
dtype = getattr(dtype, "dtype", dtype)
271274
if isinstance(dtype, str) and dtype.startswith("Sparse"):
272275
sub_type, _ = cls._parse_subtype(dtype)

0 commit comments

Comments
 (0)