Skip to content

Commit a687e1f

Browse files
committed
CLN/ENH: Restructure Dtypes and add typing info
1 parent df9762e commit a687e1f

File tree

6 files changed

+35
-65
lines changed

6 files changed

+35
-65
lines changed

pandas-stubs/core/arrays/boolean.pyi

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import numpy as np
22

3-
from pandas._typing import (
4-
Scalar,
5-
type_t,
6-
)
3+
from pandas._libs.missing import NAType
4+
from pandas._typing import type_t
75

86
from pandas.core.dtypes.base import ExtensionDtype as ExtensionDtype
97

@@ -12,11 +10,7 @@ from .masked import BaseMaskedArray as BaseMaskedArray
1210
class BooleanDtype(ExtensionDtype):
1311
name: str = ...
1412
@property
15-
def na_value(self) -> Scalar: ...
16-
@property
17-
def type(self) -> type_t: ...
18-
@property
19-
def kind(self) -> str: ...
13+
def na_value(self) -> NAType: ...
2014
@classmethod
2115
def construct_array_type(cls) -> type_t[BooleanArray]: ...
2216
def __from_arrow__(self, array): ...

pandas-stubs/core/arrays/integer.pyi

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1+
import numpy as np
2+
3+
from pandas._libs.missing import NAType
4+
15
from pandas.core.dtypes.base import ExtensionDtype as ExtensionDtype
26

37
from .masked import BaseMaskedArray
48

5-
_type = type
6-
79
class _IntegerDtype(ExtensionDtype):
8-
name: str
9-
base = ...
10-
type: _type
11-
na_value = ...
12-
def is_signed_integer(self): ...
13-
def is_unsigned_integer(self): ...
14-
def numpy_dtype(self): ...
15-
def kind(self): ...
16-
def itemsize(self): ...
10+
base: None
11+
@property
12+
def na_value(self) -> NAType: ...
13+
@property
14+
def is_signed_integer(self) -> bool: ...
15+
@property
16+
def is_unsigned_integer(self) -> bool: ...
17+
@property
18+
def numpy_dtype(self) -> np.dtype: ...
19+
@property
20+
def itemsize(self) -> int: ...
1721
@classmethod
18-
def construct_array_type(cls): ...
22+
def construct_array_type(cls) -> type[IntegerArray]: ...
1923
def __from_arrow__(self, array): ...
2024

21-
def safe_cast(values, dtype, copy): ...
22-
def coerce_to_array(values, dtype, mask=..., copy: bool = ...): ...
23-
2425
class IntegerArray(BaseMaskedArray):
2526
def dtype(self): ...
2627
def __init__(self, values, mask, copy: bool = ...) -> None: ...

pandas-stubs/core/arrays/numpy_.pyi

+5-13
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,16 @@ from pandas.core.arrays.base import (
55
ExtensionOpsMixin,
66
)
77

8+
from pandas._typing import npt
9+
810
from pandas.core.dtypes.dtypes import ExtensionDtype
911

1012
class PandasDtype(ExtensionDtype):
11-
def __init__(self, dtype) -> None: ...
12-
@property
13-
def numpy_dtype(self): ...
14-
@property
15-
def name(self): ...
16-
@property
17-
def type(self): ...
18-
@classmethod
19-
def construct_from_string(cls, string): ...
20-
@classmethod
21-
def construct_array_type(cls): ...
13+
def __init__(self, dtype: npt.DTypeLike) -> None: ...
2214
@property
23-
def kind(self): ...
15+
def numpy_dtype(self) -> np.dtype: ...
2416
@property
25-
def itemsize(self): ...
17+
def itemsize(self) -> int: ...
2618

2719
class PandasArray(ExtensionArray, ExtensionOpsMixin, NDArrayOperatorsMixin):
2820
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): ...
+9-20
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
1+
import numpy as np
2+
13
from pandas._typing import (
24
Dtype,
35
Scalar,
6+
npt,
47
)
58

69
from pandas.core.dtypes.base import ExtensionDtype
710
from pandas.core.dtypes.dtypes import (
811
register_extension_dtype as register_extension_dtype,
912
)
1013

11-
# merged types from pylance
12-
1314
class SparseDtype(ExtensionDtype):
14-
def __init__(self, dtype: Dtype = ..., fill_value: Scalar | None = ...) -> None: ...
15-
def __hash__(self): ...
16-
def __eq__(self, other) -> bool: ...
17-
@property
18-
def fill_value(self): ...
19-
@property
20-
def kind(self): ...
21-
@property
22-
def type(self): ...
15+
def __init__(
16+
self, dtype: Dtype | npt.DTypeLike = ..., fill_value: Scalar | None = ...
17+
) -> None: ...
2318
@property
24-
def subtype(self): ...
19+
def fill_value(self) -> Scalar | None: ...
2520
@property
26-
def name(self): ...
27-
@classmethod
28-
def construct_array_type(cls): ...
29-
@classmethod
30-
def construct_from_string(cls, string): ...
31-
@classmethod
32-
def is_dtype(cls, dtype): ...
33-
def update_dtype(self, dtype): ...
21+
def subtype(self) -> Dtype: ...
22+
def update_dtype(self, dtype: SparseDtype | npt.DTypeLike): ...

pandas-stubs/core/arrays/string_.pyi

-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@ import numpy as np
44
import pandas as pd
55
from pandas.core.arrays import PandasArray
66

7-
from pandas._typing import type_t
8-
97
from pandas.core.dtypes.base import ExtensionDtype
108

119
class StringDtype(ExtensionDtype):
1210
def __init__(self, storage: Literal["python", "pyarrow"] | None) -> None: ...
13-
@property
14-
def type(self) -> type_t: ...
1511
def __from_arrow__(self, array): ...
1612

1713
class StringArray(PandasArray):

pandas-stubs/core/dtypes/base.pyi

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ from pandas.core.arrays import ExtensionArray
33
from pandas._typing import type_t
44

55
class ExtensionDtype:
6-
def __eq__(self, other) -> bool: ...
7-
def __hash__(self) -> int: ...
8-
def __ne__(self, other) -> bool: ...
96
@property
107
def na_value(self): ...
118
@property
@@ -16,10 +13,11 @@ class ExtensionDtype:
1613
def name(self) -> str: ...
1714
@property
1815
def names(self) -> list[str] | None: ...
16+
def empty(self, size: int | tuple[int, ...]) -> type_t[ExtensionArray]: ...
1917
@classmethod
2018
def construct_array_type(cls) -> type_t[ExtensionArray]: ...
2119
@classmethod
22-
def construct_from_string(cls, string: str): ...
20+
def construct_from_string(cls, string: str) -> ExtensionDtype: ...
2321
@classmethod
2422
def is_dtype(cls, dtype) -> bool: ...
2523

0 commit comments

Comments
 (0)