-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
BUG: When applying Series.clip
to ordered categorical data, the outcome is different from what is expected
#49217
Comments
Hi @vitalizzare The docs for This would work: could workaround the issue like this : Lines 8025 to 8048 in 890d097
|
A late follow-up: If you look at the code for 'NDFrame.clip', it can be seen that the method is intended for non-numeric data also and I can see clipping ordered categorical data has a use case. So IMO the doc string is not accurate @vamsi-verma-s. I agree this is a bug. A PR would be welcome. |
This is interesting, here is a big one:
|
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
Issue Description
Let's say we have a series of ordered categorical data (see a series
s
in the code above). If I apply to it a methodclip
with only one oflower=
orupper=
parameters, I get the expected output, see columns 1, 2 in the below output example. But if both of them are passed then the output is different from the expected['two','two','two','three','four','four',four']
series, see the last column:Also I noticed that swapping of the values for
lower=..., upper=...
doesn't change the result, i.e.s.clip(lower='two',upper='four') == s.clip(lower='four',upper='two')
.The issue may be caused by this part (lines 8147-8153) in pandas.core.generic:
Expected Behavior
I expect this code:
to produce this output:
Installed Versions
INSTALLED VERSIONS
commit : 91111fd
python : 3.10.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Russian_Ukraine.1251
pandas : 1.5.1
numpy : 1.23.4
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 63.2.0
pip : 22.3
Cython : None
pytest : 7.1.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.1
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.5.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.6.1
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None
The text was updated successfully, but these errors were encountered: