Skip to content

Commit c7929fd

Browse files
committed
floating array
1 parent ad8cae5 commit c7929fd

File tree

11 files changed

+1166
-341
lines changed

11 files changed

+1166
-341
lines changed

pandas-stubs/_typing.pyi

Lines changed: 205 additions & 133 deletions
Large diffs are not rendered by default.
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from pandas.core.arrays.numeric import NumericDtype
1+
from pandas.core.arrays.numeric import (
2+
NumericArray,
3+
NumericDtype,
4+
)
25

36
class Float32Dtype(NumericDtype): ...
47
class Float64Dtype(NumericDtype): ...
8+
class FloatingArray(NumericArray): ...
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
from pandas.core.arrays.masked import BaseMaskedArray
2+
3+
from pandas._libs.properties import cache_readonly
4+
15
from pandas.core.dtypes.dtypes import BaseMaskedDtype
26

37
class NumericDtype(BaseMaskedDtype): ...
8+
9+
class NumericArray(BaseMaskedArray):
10+
@cache_readonly
11+
def dtype(self) -> NumericDtype: ...

pandas-stubs/core/construction.pyi

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,43 @@ from typing import overload
44
import numpy as np
55
from pandas.core.arrays.base import ExtensionArray
66
from pandas.core.arrays.boolean import BooleanArray
7+
from pandas.core.arrays.floating import FloatingArray
78
from pandas.core.arrays.integer import IntegerArray
89

910
from pandas._libs.missing import NAType
1011
from pandas._typing import (
11-
BooleanDtypeArg,
12-
IntDtypeArg,
13-
UIntDtypeArg,
12+
PandasBooleanDtypeArg,
13+
PandasFloatDtypeArg,
14+
PandasIntDtypeArg,
15+
PandasUIntDtypeArg,
16+
np_ndarray_anyint,
17+
np_ndarray_bool,
18+
np_ndarray_float,
1419
)
1520

1621
from pandas.core.dtypes.dtypes import ExtensionDtype
1722

1823
@overload
1924
def array( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
20-
data: Sequence[bool | NAType | None],
21-
dtype: BooleanDtypeArg | None = None,
25+
data: Sequence[bool | np.bool | NAType | None] | np_ndarray_bool | BooleanArray,
26+
dtype: PandasBooleanDtypeArg | None = None,
2227
copy: bool = True,
2328
) -> BooleanArray: ...
2429
@overload
25-
def array(
26-
data: Sequence[int | NAType | None],
27-
dtype: IntDtypeArg | UIntDtypeArg | None = None,
30+
def array( # type: ignore[overload-overlap]
31+
data: Sequence[int | np.integer | NAType | None] | np_ndarray_anyint | IntegerArray,
32+
dtype: PandasIntDtypeArg | PandasUIntDtypeArg | None = None,
2833
copy: bool = True,
2934
) -> IntegerArray: ...
3035
@overload
36+
def array(
37+
data: (
38+
Sequence[float | np.floating | NAType | None] | np_ndarray_float | FloatingArray
39+
),
40+
dtype: PandasFloatDtypeArg | None = None,
41+
copy: bool = True,
42+
) -> FloatingArray: ...
43+
@overload
3144
def array(
3245
data: Sequence[object],
3346
dtype: str | np.dtype | ExtensionDtype | None = None,

pandas-stubs/core/indexes/base.pyi

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ from typing import (
1616
ClassVar,
1717
Generic,
1818
Literal,
19+
TypeAlias,
1920
final,
2021
overload,
2122
type_check_only,
@@ -30,6 +31,7 @@ from _typeshed import (
3031
)
3132
import numpy as np
3233
from pandas.core.arrays.boolean import BooleanArray
34+
from pandas.core.arrays.floating import FloatingArray
3335
from pandas.core.base import (
3436
ArrayIndexTimedeltaNoSeq,
3537
ElementOpsMixin,
@@ -82,6 +84,7 @@ from pandas._typing import (
8284
AnyArrayLikeInt,
8385
ArrayLike,
8486
AxesData,
87+
BuiltinFloatDtypeArg,
8588
CategoryDtypeArg,
8689
DropKeep,
8790
Dtype,
@@ -98,6 +101,10 @@ from pandas._typing import (
98101
Level,
99102
MaskType,
100103
NaPosition,
104+
NumpyFloatNot16DtypeArg,
105+
PandasAstypeFloatDtypeArg,
106+
PandasFloatDtypeArg,
107+
PyArrowFloatDtypeArg,
101108
ReindexMethod,
102109
S2_contra,
103110
Scalar,
@@ -122,6 +129,13 @@ from pandas._typing import (
122129

123130
from pandas.core.dtypes.dtypes import PeriodDtype
124131

132+
FloatNotNumpy16DtypeArg: TypeAlias = (
133+
BuiltinFloatDtypeArg
134+
| PandasFloatDtypeArg
135+
| NumpyFloatNot16DtypeArg
136+
| PyArrowFloatDtypeArg
137+
)
138+
125139
class InvalidIndexError(Exception): ...
126140

127141
class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
@@ -160,9 +174,8 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
160174
@overload
161175
def __new__(
162176
cls,
163-
data: Sequence[float | np.floating] | IndexOpsMixin[float] | np_ndarray_float,
164-
*,
165-
dtype: Literal["float"] | type_t[float | np.floating] = ...,
177+
data: Sequence[float | np.floating] | np_ndarray_float | FloatingArray,
178+
dtype: None = None,
166179
copy: bool = ...,
167180
name: Hashable = ...,
168181
tupleize_cols: bool = ...,
@@ -171,8 +184,7 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
171184
def __new__(
172185
cls,
173186
data: AxesData,
174-
*,
175-
dtype: Literal["float"] | type_t[float | np.floating],
187+
dtype: FloatNotNumpy16DtypeArg,
176188
copy: bool = ...,
177189
name: Hashable = ...,
178190
tupleize_cols: bool = ...,
@@ -361,6 +373,13 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
361373
@final
362374
def ravel(self, order: _str = ...): ...
363375
def view(self, cls=...): ...
376+
@overload
377+
def astype(
378+
self,
379+
dtype: FloatNotNumpy16DtypeArg | PandasAstypeFloatDtypeArg,
380+
copy: bool = True,
381+
) -> Index[float]: ...
382+
@overload
364383
def astype(self, dtype: DtypeArg, copy: bool = True) -> Index: ...
365384
def take(
366385
self,

0 commit comments

Comments
 (0)