2
2
Extend pandas with custom array types.
3
3
"""
4
4
5
- from typing import Any , List , Optional , Tuple , Type
5
+ from typing import TYPE_CHECKING , Any , List , Optional , Tuple , Type
6
6
7
7
import numpy as np
8
8
9
9
from pandas .errors import AbstractMethodError
10
10
11
11
from pandas .core .dtypes .generic import ABCDataFrame , ABCIndexClass , ABCSeries
12
12
13
+ if TYPE_CHECKING :
14
+ from pandas .core .arrays import ExtensionArray # noqa: F401
15
+
13
16
14
17
class ExtensionDtype :
15
18
"""
@@ -29,7 +32,6 @@ class ExtensionDtype:
29
32
30
33
* type
31
34
* name
32
- * construct_from_string
33
35
34
36
The following attributes influence the behavior of the dtype in
35
37
pandas operations
@@ -74,7 +76,7 @@ class property**.
74
76
class ExtensionDtype:
75
77
76
78
def __from_arrow__(
77
- self, array: pyarrow.Array/ ChunkedArray
79
+ self, array: Union[ pyarrow.Array, pyarrow. ChunkedArray]
78
80
) -> ExtensionArray:
79
81
...
80
82
@@ -122,11 +124,11 @@ def __eq__(self, other: Any) -> bool:
122
124
def __hash__ (self ) -> int :
123
125
return hash (tuple (getattr (self , attr ) for attr in self ._metadata ))
124
126
125
- def __ne__ (self , other ) -> bool :
127
+ def __ne__ (self , other : Any ) -> bool :
126
128
return not self .__eq__ (other )
127
129
128
130
@property
129
- def na_value (self ):
131
+ def na_value (self ) -> object :
130
132
"""
131
133
Default NA value to use for this type.
132
134
@@ -184,7 +186,7 @@ def names(self) -> Optional[List[str]]:
184
186
return None
185
187
186
188
@classmethod
187
- def construct_array_type (cls ):
189
+ def construct_array_type (cls ) -> Type [ "ExtensionArray" ] :
188
190
"""
189
191
Return the array type associated with this dtype.
190
192
@@ -250,7 +252,7 @@ def construct_from_string(cls, string: str):
250
252
return cls ()
251
253
252
254
@classmethod
253
- def is_dtype (cls , dtype ) -> bool :
255
+ def is_dtype (cls , dtype : object ) -> bool :
254
256
"""
255
257
Check if we match 'dtype'.
256
258
@@ -261,7 +263,7 @@ def is_dtype(cls, dtype) -> bool:
261
263
262
264
Returns
263
265
-------
264
- is_dtype : bool
266
+ bool
265
267
266
268
Notes
267
269
-----
0 commit comments