-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix IntervalIndex.get_loc/get_indexer for IntervalIndex of length one #20946
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -497,6 +497,14 @@ def test_get_loc_interval(self): | |
pytest.raises(KeyError, self.index.get_loc, | ||
Interval(-1, 0, 'left')) | ||
|
||
# Make consistent with test_interval_new.py (see #16316, #16386) | ||
@pytest.mark.parametrize('item', [3, Interval(1, 4)]) | ||
def test_get_loc_length_one(self, item, closed): | ||
# GH 20921 | ||
index = IntervalIndex.from_tuples([(0, 5)], closed=closed) | ||
result = index.get_loc(item) | ||
assert result == 0 | ||
|
||
# To be removed, replaced by test_interval_new.py (see #16316, #16386) | ||
def test_get_indexer(self): | ||
actual = self.index.get_indexer([-1, 0, 0.5, 1, 1.5, 2, 3]) | ||
|
@@ -544,6 +552,16 @@ def test_get_indexer_subintervals(self): | |
expected = np.array([0, 0, 0], dtype='intp') | ||
tm.assert_numpy_array_equal(actual, expected) | ||
|
||
# Make consistent with test_interval_new.py (see #16316, #16386) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this is consistent with those tests, you can remove from there I think (not sure exactly how we are tracking 'new' things vs current) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't consistent with the new tests, as the new behavior should only allow for exact matches when querying with I've taken a stab at implementing the new behavior in the past, but it looks like it will require a pretty large change, as changing one method to implement the new behavior often causes another (also with new proposed behavior) to break, so it seems like it'd at least approach an all or nothing type of change. Hopefully will carve out some time to do it fully somewhat soon. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. k that is fine. yeah converting to use the new tests is a major effort :> |
||
@pytest.mark.parametrize('item', [ | ||
[3], np.arange(1, 5), [Interval(1, 4)], interval_range(1, 4)]) | ||
def test_get_indexer_length_one(self, item, closed): | ||
# GH 17284 | ||
index = IntervalIndex.from_tuples([(0, 5)], closed=closed) | ||
result = index.get_indexer(item) | ||
expected = np.array([0] * len(item), dtype='intp') | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
# To be removed, replaced by test_interval_new.py (see #16316, #16386) | ||
def test_contains(self): | ||
# Only endpoints are valid. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reorganized here to be alphabetical.