Skip to content
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: RangeIndex problem #47128

Closed
3 tasks done
hosseinrasekhi opened this issue May 26, 2022 · 8 comments · Fixed by #47143
Closed
3 tasks done

BUG: RangeIndex problem #47128

hosseinrasekhi opened this issue May 26, 2022 · 8 comments · Fixed by #47143
Labels
Bug Copy / view semantics Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@hosseinrasekhi
Copy link

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
A = pd.DataFrame({'a':[False,True]}) # index=[0,1] vs index=range(2)
A['i'] = A.index
A.loc[A['a'],'i'] = -2
print(A.loc[A['a'],:])

Issue Description

when assign index(RangeIndex) to new column then change this column by loc, index will change unexpectedly. this issue exists in 1.4.x but not in 1.1.1

  a i
-2 True -2

Expected Behavior

  a i
1 True -2

Installed Versions

INSTALLED VERSIONS

commit : bb1f651
python : 3.9.7.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-110-generic
Version : #124-Ubuntu SMP Thu Apr 14 19:46:19 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.4.0
numpy : 1.22.2
pytz : 2022.1
dateutil : 2.8.2
pip : 21.2.3
setuptools : 49.2.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.8.0
html5lib : None
pymysql : None
psycopg2 : 2.9.1
jinja2 : 3.1.2
IPython : 7.33.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.4.3
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : 1.4.23
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
None

@hosseinrasekhi hosseinrasekhi added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 26, 2022
@nishithshowri006
Copy link

I think the behavior is different using integers and booleans, I think it is the reason you might be not getting the expected results.
image

@phofl phofl added Indexing Related to indexing on series/frames, not to indexes themselves Copy / view semantics Regression Functionality that used to work in a prior pandas version and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 27, 2022
@phofl phofl added this to the 1.4.3 milestone May 27, 2022
@phofl
Copy link
Member

phofl commented May 27, 2022

Thanks for the report.

This worked on 1.3.5 too

@simonjayhawkins
Copy link
Member

This worked on 1.3.5 too

failed? worked in 1.1.5 but not 1.2.5. will bisect to shed more light.

@phofl
Copy link
Member

phofl commented May 27, 2022

This is what I am getting on 1.3.5

A = pd.DataFrame({'a':[False,True]})
idx = A.index
A['i'] = idx
A.loc[[False, True], 'i'] = -2
print(A.loc[[1], :])

returns

      a  i
1  True -2

which is correct.

INSTALLED VERSIONS ------------------ commit : 66e3805 python : 3.9.2.final.0 python-bits : 64 OS : Linux OS-release : 5.13.0-44-generic Version : #49~20.04.1-Ubuntu SMP Wed May 18 18:44:28 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.3.5
numpy : 1.22.3
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 52.0.0.post20210125
Cython : 0.29.21
pytest : 6.2.2
hypothesis : 6.24.2
sphinx : 3.5.2
blosc : None
feather : None
xlsxwriter : 1.3.7
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.27.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 0.9.0
fastparquet : None
gcsfs : None
matplotlib : 3.3.2
numexpr : 2.8.1
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : 5.0.0
pyxlsb : None
s3fs : None
scipy : 1.6.1
sqlalchemy : 1.4.0
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
numba : None
None

simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue May 27, 2022
@simonjayhawkins
Copy link
Member

This is what I am getting on 1.3.5

ok so must be a dependency issue. I've started the bisect but it'll probably fail then.

@phofl
Copy link
Member

phofl commented May 27, 2022

Yeah probably, numpy would be my first guess.

@simonjayhawkins
Copy link
Member

I've started the bisect but it'll probably fail then.

didn't fail. i'm getting

first bad commit: [b58ee57] PERF: Index._shallow_copy shares _cache with copies of self (#36840)

which seems plausible.

@phofl
Copy link
Member

phofl commented May 27, 2022

Weird, I can only reproduce with pandas 1.4.+

Changing the numpy version did not help either

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Copy / view semantics Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants