Skip to content

BUG: clip raises when using extension array dtypes #52799

Open
@bollard

Description

@bollard

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

ser_a = pd.Series([1, 2], dtype=pd.Int64Dtype())
ser_b = pd.Series([3, pd.NA], dtype=pd.Int64Dtype())
ser_a.clip(lower=ser_b)

# TypeError: Invalid value '-inf' for dtype Int64

ser_c = pd.Series([3, pd.NA])
ser_c.dtype
# dtype('O')

ser_a.clip(lower=ser_c)
# 0    3
# 1    2
# dtype: Int64

Issue Description

Hi all,

When using extension array dtypes, clip throws a TypeError if the upper / lower series contains a pd.NA. This does not happen if we downcast the upper / lower series to type object.

Thanks

Expected Behavior

import pandas as pd

ser_a = pd.Series([1, 2], dtype=pd.Int64Dtype())
ser_b = pd.Series([3, pd.NA], dtype=pd.Int64Dtype())
ser_a.clip(lower=ser_b)
# 0    3
# 1    2
# dtype: Int64

Installed Versions

pd.show_versions()
C:\BD\TPD\Miniconda3-py37_4.10.3\envs\pandasdev\lib\site-packages_distutils_hack_init_.py:33: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")

INSTALLED VERSIONS

commit : 478d340
python : 3.10.10.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 165 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United Kingdom.1252

pandas : 2.0.0
numpy : 1.24.2
pytz : 2023.3
dateutil : 2.8.2
setuptools : 66.0.0
pip : 23.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNA - 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