Skip to content

API: change IntervalIndex.contains to work elementwise #17753

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

Merged
merged 10 commits into from
Jul 1, 2019
Prev Previous commit
Next Next commit
fixup merge
  • Loading branch information
jorisvandenbossche committed Jun 29, 2019
commit d8737e4aaaf9ca53ce22883604f20c4210f861b2
35 changes: 17 additions & 18 deletions pandas/tests/indexes/interval/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,23 @@ def test_maybe_convert_i8_errors(self, breaks1, breaks2, make_key):
with pytest.raises(ValueError, match=msg):
index._maybe_convert_i8(key)

# To be removed, replaced by test_interval_new.py (see #16316, #16386)
def test_contains(self):
# Only endpoints are valid.
i = IntervalIndex.from_arrays([0, 1], [1, 2])

# Invalid
assert 0 not in i
assert 1 not in i
assert 2 not in i

# Valid
assert Interval(0, 1) in i
assert Interval(0, 2) in i
assert Interval(0, 0.5) in i
assert Interval(3, 5) not in i
assert Interval(-1, 0, closed='left') not in i

def test_contains_method(self):
# can select values that are IN the range of a value
i = IntervalIndex.from_arrays([0, 1], [1, 2])
Expand All @@ -757,24 +774,6 @@ def test_contains_method(self):
with pytest.raises(TypeError):
i.contains(Interval(0, 1))

# To be removed, replaced by test_interval_new.py (see #16316, #16386)
def test_contains_method(self):
# can select values that are IN the range of a value
i = IntervalIndex.from_arrays([0, 1], [1, 2])

assert i.contains(0.1)
assert i.contains(0.5)
assert i.contains(1)
assert i.contains(Interval(0, 1))
assert i.contains(Interval(0, 2))

# these overlaps completely
assert i.contains(Interval(0, 3))
assert i.contains(Interval(1, 3))

assert not i.contains(20)
assert not i.contains(-20)

def test_dropna(self, closed):

expected = IntervalIndex.from_tuples(
Expand Down