Skip to content

Commit d72d9f1

Browse files
authored
Series mask method's "other" parameter does not accept pandas.NA (#725)
* Update series.pyi * Add type tests for mark * Use np.integer instead of np.int64
1 parent 894a590 commit d72d9f1

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pandas-stubs/core/series.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
13781378
def mask(
13791379
self,
13801380
cond: MaskType,
1381-
other: Scalar | Series[S1] | DataFrame | Callable = ...,
1381+
other: Scalar | Series[S1] | DataFrame | Callable | NAType | None = ...,
13821382
*,
13831383
inplace: _bool = ...,
13841384
axis: AxisIndex | None = ...,

tests/test_series.py

+17
Original file line numberDiff line numberDiff line change
@@ -2017,3 +2017,20 @@ def test_to_string() -> None:
20172017
),
20182018
str,
20192019
)
2020+
2021+
2022+
def test_types_mask() -> None:
2023+
s = pd.Series([1, 2, 3, 4, 5])
2024+
2025+
# Test case with a boolean condition and a scalar value
2026+
check(assert_type(s.mask(s > 3, 10), pd.Series), pd.Series, np.integer)
2027+
2028+
# Test case with a boolean condition and a callable
2029+
def double(x):
2030+
return x * 2
2031+
2032+
check(assert_type(s.mask(s > 3, double), pd.Series), pd.Series, np.integer)
2033+
2034+
# Test cases with None and pd.NA as other
2035+
check(assert_type(s.mask(s > 3, None), pd.Series), pd.Series, np.float64)
2036+
check(assert_type(s.mask(s > 3, pd.NA), pd.Series), pd.Series, np.float64)

0 commit comments

Comments
 (0)