DataFrame.clip() bug when bound a frame when columns not sorted · Issue #20911 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

In [14]: import pandas as pd

In [15]: df1 = pd.DataFrame([[1., 0.], [3., 0.]], columns=['A', 'B'])

In [16]: df2 = pd.DataFrame([[100., 1.], [100., 2.]], columns=['B', 'A'])

In [17]: df1.clip(lower=0, upper=df2) Out[17]: A B 0 1.0 0.0 1 100.0 0.0 In [18]: df1 Out[18]: A B 0 1.0 0.0 1 3.0 0.0

selecting columns in order produces the correct results

In [20]: df1.clip(lower=0, upper=df2[df1.columns]) Out[20]: A B 0 1.0 0.0 1 2.0 0.0

Problem description

The behavior was correct in 0.18.1. df1.A = 3.0 is being clipped to 100.0. This not expected.

Expected Output

In [39]: df1.clip(lower=0, upper=df2) Out[39]: A B 0 1.0 0.0 1 2.0 0.0

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.14.final.0
python-bits: 64
OS: Linux
OS-release: 3.10.0-327.36.3.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: C
LANG: en_US.UTF-8
LOCALE: None.None

pandas: 0.22.0
pytest: 3.5.0
pip: 9.0.3
setuptools: 39.0.1
Cython: 0.28.2
numpy: 1.14.2
scipy: 1.0.1
pyarrow: 0.9.0
xarray: 0.10.2
IPython: 5.6.0
sphinx: 1.7.2
patsy: 0.5.0
dateutil: 2.7.2
pytz: 2018.4
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.2.2
openpyxl: 2.5.2
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.2.1
bs4: 4.3.2
html5lib: 0.999
sqlalchemy: 1.2.6
pymysql: None
psycopg2: 2.7.4 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None