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

Inconsistent behaviour on empty RangeIndex intersection #14364

Closed
maxencedb opened this issue Oct 6, 2016 · 1 comment
Closed

Inconsistent behaviour on empty RangeIndex intersection #14364

maxencedb opened this issue Oct 6, 2016 · 1 comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@maxencedb
Copy link

maxencedb commented Oct 6, 2016

Description of the issue

Two empty RangeIndex objects with same starts and stops will have a non-null intersection.

Code example

import pandas as pd

# Two empty rangeindexes
a = pd.RangeIndex(0, 0)
b = pd.RangeIndex(0, 0)

# Also empty but different start and stops
c = pd.RangeIndex(1, 1)

# OK, this returns an empty Index
print(a.intersection(c))

# Strangely, this one returns an index of [0, 1[
print(a.intersection(b))

Expected output

RangeIndex(start=0, stop=0, step=1)
RangeIndex(start=0, stop=0, step=1)

Output

RangeIndex(start=0, stop=0, step=1)
RangeIndex(start=0, stop=1, step=1)

Output of pd.show_versions()

Not the most recent version of Pandas, but I believe this behaviour is still present in the master branch
after browsing the code. If somebody could confirm.

## INSTALLED VERSIONS

commit: None
python: 2.7.10.final.0
python-bits: 64
OS: Linux
OS-release: None
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.1
setuptools: 24.0.2
numpy: 1.10.1
dateutil: 1.5
pytz: 2015.4

@maxencedb maxencedb changed the title Inconsistent behaviour on empty IndexRange intersection Inconsistent behaviour on empty RangeIndex intersection Oct 6, 2016
@jorisvandenbossche
Copy link
Member

Actually, with pandas 0.19.0, it is even worse: first example gives an error, the second is still the wrong output:

In [2]: a.intersection(c)
...
TypeError: RangeIndex(...) must be called with integers

In [3]: a.intersection(b)
Out[3]: RangeIndex(start=0, stop=1, step=1)

In [4]: a.intersection(b).values
Out[4]: array([0])

Thanks for the report!

@jorisvandenbossche jorisvandenbossche added Bug Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version labels Oct 6, 2016
@jorisvandenbossche jorisvandenbossche added this to the 0.19.1 milestone Oct 6, 2016
jorisvandenbossche added a commit to jorisvandenbossche/pandas that referenced this issue Nov 2, 2016
… (GH14364)

closes pandas-dev#14364

Author: Joris Van den Bossche <jorisvandenbossche@gmail.com>

Closes pandas-dev#14481 from jorisvandenbossche/bug-rangeindex-empty and squashes the following commits:

823e83d [Joris Van den Bossche] BUG: fix empty intersection of RangeIndex (GH14364)

(cherry picked from commit fe2ebc1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 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.

2 participants