You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When inserting an entire column using the loc function and a boolean index we observe the the values are not inserted in the correct order.
This only happens when the entire column is changed, i.e. the entire boolean array is True, and if there is a datetime column in the dataframe.
Expected Behavior
This behavior was tested in pandas 1.4.4 and the problem wasn't observed here.
The two below examples behave as expected and retains the data order.
# Works with one not True
df = pd.DataFrame({'Time': [dt.datetime.now() - dt.timedelta(hours=i) for i in range(l)], 'A': vals, 'B': vals, 'C': vals})
data = df.copy()
df.loc[[True for _ in range(l-1)] + [False], ['A', 'B']] = df.loc[[True for _ in range(l-1)] + [False], ['A', 'B']]
print(data.equals(df))
# Works with only float/int data
df = pd.DataFrame({'A': vals, 'B': vals, 'C': vals})
data = df.copy()
df.loc[[True for _ in range(l)], ['A', 'B']] = df.loc[[True for _ in range(l)], ['A', 'B']]
print(data.equals(df))
Installed Versions
INSTALLED VERSIONS
commit : 87cfe4e
python : 3.9.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22000
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Danish_Denmark.1252
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
When inserting an entire column using the loc function and a boolean index we observe the the values are not inserted in the correct order.
This only happens when the entire column is changed, i.e. the entire boolean array is True, and if there is a datetime column in the dataframe.
Expected Behavior
This behavior was tested in pandas 1.4.4 and the problem wasn't observed here.
The two below examples behave as expected and retains the data order.
Installed Versions
INSTALLED VERSIONS
commit : 87cfe4e
python : 3.9.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22000
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Danish_Denmark.1252
pandas : 1.5.0
numpy : 1.23.3
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 62.1.0
pip : 22.1.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
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
xlwt : None
zstandard : None
tzdata : None
The text was updated successfully, but these errors were encountered: