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.where throws AssertionError #43240

Closed
2 of 3 tasks
galipremsagar opened this issue Aug 26, 2021 · 1 comment · Fixed by #43251
Closed
2 of 3 tasks

BUG: RangeIndex.where throws AssertionError #43240

galipremsagar opened this issue Aug 26, 2021 · 1 comment · Fixed by #43251
Labels
Bug Index Related to the Index class or subclasses Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@galipremsagar
Copy link

galipremsagar commented Aug 26, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

>>> import pandas as pd
>>> pd.__version__
'1.3.2'
>>> s = pd.RangeIndex(0, 5)
>>> s
RangeIndex(start=0, stop=5, step=1)
>>> import numpy as np
>>> v = np.array([False, False, True, True, True])
>>> s.where(v, 10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pgali/anaconda3/envs/cudf_dev/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 4472, in where
    return self.putmask(~cond, other)
  File "/home/pgali/anaconda3/envs/cudf_dev/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 4727, in putmask
    return type(self)._simple_new(values, name=self.name)
  File "/home/pgali/anaconda3/envs/cudf_dev/lib/python3.8/site-packages/pandas/core/indexes/range.py", line 164, in _simple_new
    assert isinstance(values, range)
AssertionError

Problem description

pandas RangeIndex is not allowing a where operation to be performed which was working in older versions of pandas i.e., 1.2.5

Expected Output

>>> import pandas as pd
>>> pd.__version__
'1.2.5'
>>> s = pd.RangeIndex(0, 5)
>>> s
RangeIndex(start=0, stop=5, step=1)
>>> import numpy as np
>>> v = np.array([False, False, True, True, True])
>>> s.where(v, 10)
Int64Index([10, 10, 2, 3, 4], dtype='int64')

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 5f648bf
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.11.0-27-generic
Version : #29~20.04.1-Ubuntu SMP Wed Aug 11 15:58:17 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.2
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 57.4.0
Cython : 0.29.24
pytest : 6.2.4
hypothesis : 6.15.0
sphinx : 4.1.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.26.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : 2021.07.0
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 5.0.0
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.53.1

@galipremsagar galipremsagar added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 26, 2021
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Aug 27, 2021
@simonjayhawkins simonjayhawkins added Index Related to the Index class or subclasses 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 Aug 27, 2021
@simonjayhawkins simonjayhawkins added this to the 1.3.3 milestone Aug 27, 2021
@simonjayhawkins
Copy link
Member

Thanks @galipremsagar for the report

first bad commit: [6b8cc98] BUG: make Index.where behavior mirror Index.putmask behavior (#39412)

cc @jbrockmendel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Index Related to the Index class or subclasses Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants