Skip to content

Series mask method's "other" parameter does not accept pandas.NA #725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
def mask(
self,
cond: MaskType,
other: Scalar | Series[S1] | DataFrame | Callable = ...,
other: Scalar | Series[S1] | DataFrame | Callable | NAType | None = ...,
*,
inplace: _bool = ...,
axis: AxisIndex | None = ...,
Expand Down
17 changes: 17 additions & 0 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2014,3 +2014,20 @@ def test_to_string() -> None:
),
str,
)


def test_types_mask() -> None:
s = pd.Series([1, 2, 3, 4, 5])

# Test case with a boolean condition and a scalar value
check(assert_type(s.mask(s > 3, 10), pd.Series), pd.Series, np.integer)

# Test case with a boolean condition and a callable
def double(x):
return x * 2

check(assert_type(s.mask(s > 3, double), pd.Series), pd.Series, np.integer)

# Test cases with None and pd.NA as other
check(assert_type(s.mask(s > 3, None), pd.Series), pd.Series, np.float64)
check(assert_type(s.mask(s > 3, pd.NA), pd.Series), pd.Series, np.float64)