Skip to content

BUG: setting value to a entire column using .loc may result out of the order rows #48992

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
3 tasks done
AlbertOh90 opened this issue Oct 7, 2022 · 1 comment
Closed
3 tasks done
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@AlbertOh90
Copy link

AlbertOh90 commented Oct 7, 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

Hello, there seems to be a bug in the Pandas 1.5.0 .loc function. When setting values to the .loc, if the callable condition is True for all the rows, then the rows of the assigned columns are out of the order
To reproduce
import pandas as pd
input_df = pd.DataFrame({
    'A': [1] * 17,
    'B': [''] * 17})
a = np.array([0, 10, 10, 20, 20, 30, 30, 30, 10, 10, 20, 20, 0, 0, 0, 10, 10])
input_df.loc[[True]*17, 'A'] = a
print(input_df)

Issue Description

This will only happen when the number of rows is bigger than 16.
To solve this, either make sure the values setting to .loc is a pd.Series type, or use colon: instead of conditions
input_df.loc[:, 'A'] = a

Expected Behavior

import pandas as pd
input_df = pd.DataFrame({
'A': [1] * 17,
'B': [''] * 17})
a = np.array([0, 10, 10, 20, 20, 30, 30, 30, 10, 10, 20, 20, 0, 0, 0, 10, 10])
input_df.loc[:, 'A'] = a
print(input_df)

Installed Versions

INSTALLED VERSIONS

commit : 87cfe4e
python : 3.10.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.14.0-1052-oem
Version : #59-Ubuntu SMP Fri Sep 9 09:37:59 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.0
numpy : 1.22.1
pytz : 2022.4
dateutil : 2.8.2
setuptools : 60.2.0
pip : 21.3.1
Cython : None
pytest : 7.1.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.3
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 : 1.0.9
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.6.0
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.1
snappy : None
sqlalchemy : None
tables : None
tabulate : 0.8.10
xarray : None
xlrd : None
xlwt : 1.3.0
zstandard : None
tzdata : None
None

@AlbertOh90 AlbertOh90 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 7, 2022
@phofl
Copy link
Member

phofl commented Oct 7, 2022

Hi, thanks for your report. This is a duplicate and is already fixed for 1.5.1

@phofl phofl closed this as completed Oct 7, 2022
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

2 participants