Skip to content

BUG: Mask changing value despite of no True return #61505

@frbelotto

Description

@frbelotto

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

data = {'cd_tip_fma_pgto': [pd.NA]}
df = pd.DataFrame(data, dtype='double[pyarrow]')
df['payment'] = np.nan
df['payment'] = df['payment'].mask(cond=(df['cd_tip_fma_pgto'] == 6), other='Livelo')

Issue Description

Evaluating the mask method under a pd.NA, when using pyarrow, is changing the target value!

Image

Expected Behavior

The results of the compasison should not cause any change of the target value, as you see in this example :

data = {'cd_tip_fma_pgto': [pd.NA]}
df = pd.DataFrame(data)
df['payment'] = np.nan
df['payment'] = df['payment'].mask(cond=(df['cd_tip_fma_pgto'] == 6), other='Livelo')

Image

Installed Versions

INSTALLED VERSIONS

commit : 0691c5c
python : 3.11.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-1127.19.1.el7.x86_64
Version : #1 SMP Tue Aug 25 17:23:54 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_US.UTF-8

pandas : 2.2.3
numpy : 1.24.2
pytz : 2022.7.1
dateutil : 2.8.2
pip : 25.1.1
Cython : 0.29.33
sphinx : None
IPython : 8.10.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.11.2
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.5.0
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.2
lxml.etree : 4.9.2
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.3
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 17.0.0
pyreadstat : None
pytest : 7.4.3
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
sqlalchemy : 2.0.30
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2024.1
qtpy : N/A
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions