5
5
Any ,
6
6
Callable ,
7
7
Literal ,
8
+ cast ,
8
9
overload ,
9
10
)
10
11
import warnings
16
17
missing as libmissing ,
17
18
)
18
19
from pandas ._libs .tslibs import is_supported_dtype
19
- from pandas ._typing import (
20
- ArrayLike ,
21
- AstypeArg ,
22
- AxisInt ,
23
- DtypeObj ,
24
- FillnaOptions ,
25
- InterpolateOptions ,
26
- NpDtype ,
27
- PositionalIndexer ,
28
- Scalar ,
29
- ScalarIndexer ,
30
- Self ,
31
- SequenceIndexer ,
32
- Shape ,
33
- npt ,
34
- )
35
20
from pandas .compat import (
36
21
IS64 ,
37
22
is_platform_windows ,
97
82
from pandas ._typing import (
98
83
NumpySorter ,
99
84
NumpyValueArrayLike ,
85
+ ArrayLike ,
86
+ AstypeArg ,
87
+ AxisInt ,
88
+ DtypeObj ,
89
+ FillnaOptions ,
90
+ InterpolateOptions ,
91
+ NpDtype ,
92
+ PositionalIndexer ,
93
+ Scalar ,
94
+ ScalarIndexer ,
95
+ Self ,
96
+ SequenceIndexer ,
97
+ Shape ,
98
+ npt ,
100
99
)
101
100
from pandas ._libs .missing import NAType
102
101
from pandas .core .arrays import FloatingArray
@@ -111,16 +110,10 @@ class BaseMaskedArray(OpsMixin, ExtensionArray):
111
110
numpy based
112
111
"""
113
112
114
- # The value used to fill '_data' to avoid upcasting
115
- _internal_fill_value : Scalar
116
113
# our underlying data and mask are each ndarrays
117
114
_data : np .ndarray
118
115
_mask : npt .NDArray [np .bool_ ]
119
116
120
- # Fill values used for any/all
121
- _truthy_value = Scalar # bool(_truthy_value) = True
122
- _falsey_value = Scalar # bool(_falsey_value) = False
123
-
124
117
@classmethod
125
118
def _simple_new (cls , values : np .ndarray , mask : npt .NDArray [np .bool_ ]) -> Self :
126
119
result = BaseMaskedArray .__new__ (cls )
@@ -155,8 +148,9 @@ def _from_sequence(cls, scalars, *, dtype=None, copy: bool = False) -> Self:
155
148
@classmethod
156
149
@doc (ExtensionArray ._empty )
157
150
def _empty (cls , shape : Shape , dtype : ExtensionDtype ) -> Self :
158
- values = np .empty (shape , dtype = dtype .type )
159
- values .fill (cls ._internal_fill_value )
151
+ dtype = cast (BaseMaskedDtype , dtype )
152
+ values : np .ndarray = np .empty (shape , dtype = dtype .type )
153
+ values .fill (dtype ._internal_fill_value )
160
154
mask = np .ones (shape , dtype = bool )
161
155
result = cls (values , mask )
162
156
if not isinstance (result , cls ) or dtype != result .dtype :
@@ -917,7 +911,9 @@ def take(
917
911
) -> Self :
918
912
# we always fill with 1 internally
919
913
# to avoid upcasting
920
- data_fill_value = self ._internal_fill_value if isna (fill_value ) else fill_value
914
+ data_fill_value = (
915
+ self .dtype ._internal_fill_value if isna (fill_value ) else fill_value
916
+ )
921
917
result = take (
922
918
self ._data ,
923
919
indexer ,
@@ -1397,12 +1393,7 @@ def any(
1397
1393
nv .validate_any ((), kwargs )
1398
1394
1399
1395
values = self ._data .copy ()
1400
- # error: Argument 3 to "putmask" has incompatible type "object";
1401
- # expected "Union[_SupportsArray[dtype[Any]],
1402
- # _NestedSequence[_SupportsArray[dtype[Any]]],
1403
- # bool, int, float, complex, str, bytes,
1404
- # _NestedSequence[Union[bool, int, float, complex, str, bytes]]]"
1405
- np .putmask (values , self ._mask , self ._falsey_value ) # type: ignore[arg-type]
1396
+ np .putmask (values , self ._mask , self .dtype ._falsey_value )
1406
1397
result = values .any ()
1407
1398
if skipna :
1408
1399
return result
@@ -1490,12 +1481,7 @@ def all(
1490
1481
nv .validate_all ((), kwargs )
1491
1482
1492
1483
values = self ._data .copy ()
1493
- # error: Argument 3 to "putmask" has incompatible type "object";
1494
- # expected "Union[_SupportsArray[dtype[Any]],
1495
- # _NestedSequence[_SupportsArray[dtype[Any]]],
1496
- # bool, int, float, complex, str, bytes,
1497
- # _NestedSequence[Union[bool, int, float, complex, str, bytes]]]"
1498
- np .putmask (values , self ._mask , self ._truthy_value ) # type: ignore[arg-type]
1484
+ np .putmask (values , self ._mask , self .dtype ._truthy_value )
1499
1485
result = values .all (axis = axis )
1500
1486
1501
1487
if skipna :
0 commit comments