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

Comments

Projects
None yet
2 participants
@maxencedb

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 from Inconsistent behaviour on empty IndexRange intersection to Inconsistent behaviour on empty RangeIndex intersection Oct 6, 2016

@jorisvandenbossche

This comment has been minimized.

Show comment
Hide comment
@jorisvandenbossche

jorisvandenbossche Oct 6, 2016

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!

Member

jorisvandenbossche commented Oct 6, 2016

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 this to the 0.19.1 milestone Oct 6, 2016

@jreback jreback closed this in fe2ebc1 Oct 24, 2016

jorisvandenbossche added a commit to jorisvandenbossche/pandas that referenced this issue Nov 2, 2016

[Backport #14481] BUG: fix empty intersection of RangeIndex (GH14364)
closes #14364

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

Closes #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)

amolkahat added a commit to amolkahat/pandas that referenced this issue Nov 26, 2016

BUG: fix empty intersection of RangeIndex (GH14364)
closes #14364

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

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

823e83d [Joris Van den Bossche] BUG: fix empty intersection of RangeIndex (GH14364)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment