Skip to content

BUG: clip function works with float arrays but not ExtendedArrays (similar problem to #45778) #45955

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

Closed
1 of 3 tasks
MichaelTiemannOSC opened this issue Feb 12, 2022 · 2 comments
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@MichaelTiemannOSC
Copy link
Contributor

MichaelTiemannOSC commented Feb 12, 2022

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
import pint_pandas
from pint_pandas import PintArray as PA_

xx = pd.DataFrame(PA_([1.,2.,3.],dtype='pint[m]'))
yy = PA_([10.,10.,10.],dtype='pint[m]')
zz = PA_([0.,0.,0.],dtype='pint[m]')

# Clip 1,2,3 against lower bound of 10,10,10 results in 10,10,10
xx.clip(lower=yy, axis=0)
#       0
# 0  10.0
# 1  10.0
# 2  10.0

# Clip 1,2,3 against lower bound of 0,0,0 should result in 1,2,3
xx.clip(lower=zz, axis=0)
# *** IndexError: index 0 is out of bounds for axis 0 with size 0

Issue Description

This problem smacks of the recently merged regression identified here: #45778

But this is not a problem with the .loc indexer, but elsewhere. Most likely the where function in blocks.py, line 1634 in the 1.4.0 release. Maybe the fix is very simple: in function (def where(self, other, cond, errors="raise") -> list[Block]:
) replace

        try:
            result[icond] = set_other

with

        try:
            if icond.any():
                result[icond] = set_other

Expected Behavior

I expect that a clip action that is supposed to do nothing will do nothing, not throw an error about a zero-sized array that's unable to handle a zero-sized update of nothingness.

Installed Versions

INSTALLED VERSIONS

commit : 66e3805
python : 3.9.9.final.0
python-bits : 64
OS : Darwin
OS-release : 21.3.0
Version : Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.5
numpy : 1.22.0
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3.1
setuptools : 60.3.1
Cython : 0.29.26
pytest : None
hypothesis : None
sphinx : 4.3.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.31.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : 1.3.2
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : 2.8.0
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
numba : None

@MichaelTiemannOSC MichaelTiemannOSC added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 12, 2022
@MichaelTiemannOSC MichaelTiemannOSC changed the title BUG: BUG: clip function works with float arrays but not ExtendedArrays (similar problem to #45778) Feb 13, 2022
@MichaelTiemannOSC
Copy link
Contributor Author

This was true for version 1.3.5 but not yet checked for 1.4.1.

@MichaelTiemannOSC
Copy link
Contributor Author

Apparently fixed since 1.3.5. Good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant