Skip to content

BUG: Bug in mask method when handling pd.NA with Int64Dtype #60794

@IceyDuan

Description

@IceyDuan

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
from pandas import Series
from pandas.api.extensions import Int64Dtype
series = Series([None, 1, 2, None, 3, 4, None], dtype=Int64Dtype())
result = series.mask(series <= 2, -99)
print(result)

Issue Description

I am encountering an issue with the mask method in pandas when it is used with a Series of type Int64Dtype. Specifically, when trying to mask pd.NA values, they are being replaced, which is not the expected behavior. I expected the pd.NA values to remain unchanged, but they are being incorrectly filled.

Expected Behavior

Series([None, -99, -99, None, 3, 4, None], dtype=Int64Dtype())

Installed Versions

python: 3.11.1
pandas: 2.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDuplicate ReportDuplicate issue or pull requestNA - MaskedArraysRelated to pd.NA and nullable extension arrays

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions