-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
New Interval / IntervalIndex behavior spec #16386
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 49 commits
18c76f4
ddc508c
a1c3e7a
557d701
7d28038
ff1fbf2
aadfdcd
c7f6fb8
1379b08
80ebeb3
fef3187
e3a12fa
06a2835
08bd9e4
6381744
b346af7
ccd23aa
ac818f9
4a10007
e549c3d
d5a8287
0e50729
2c953b6
08d315c
9f905a8
e1eeb59
4c54f33
ca04cb2
bfaefef
ce5074a
4c5496e
33938d6
7f4c5e5
0aaaddf
a44c926
4cef040
66486d0
c0dfef8
5301dd5
57c9ba7
4cbbf2d
6126662
dc00af6
604d48d
10c9177
c8be3e6
93f1742
3464883
06484f5
e82ae33
6834c9a
33ebe1b
be050d6
1cc8004
930da2b
2e01d28
5c000a0
96c978a
ae03d01
518d16e
f530637
d90d310
acefcb0
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 |
---|---|---|
|
@@ -595,6 +595,7 @@ def test_repr_max_seq_item_setting(self): | |
def test_repr_roundtrip(self): | ||
super(TestIntervalIndex, self).test_repr_roundtrip() | ||
|
||
# TODO: check this behavior is consistent | ||
def test_get_item(self, closed): | ||
i = IntervalIndex.from_arrays((0, 1, np.nan), (1, 2, np.nan), | ||
closed=closed) | ||
|
@@ -615,6 +616,7 @@ def test_get_item(self, closed): | |
closed=closed) | ||
tm.assert_index_equal(result, expected) | ||
|
||
# To be removed (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. Why? Could you briefly explain in the comments? 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. Those questions BTW apply to all comments where you write this. 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. maybe reference test_interval_new.py directly (as well as the issues numbers), so its obvious to a reader what is happening. |
||
def test_get_loc_value(self): | ||
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. to the extent you are adding new tests that are xfailing, but let's these these where they are for now. actually let's put all of your new tests in a new file, its going to be much more obvious. This way all existing behavior is preserved (as we have not changed anything). You can certainly mark existing tests (maybe with a comment), that this is going to change. 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. That was the way I had it before, but @jorisvandenbossche (I believe it was you?) asked that I remove the current tests instead. I'm happy to go back to what I had before, but please settle this amongst yourselves so we don't revert a third time. 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. it was not me who asked, but that doesn't matter anymore. I think we agree now to go this route. I don't think you should 'go back to what you had before', I think you should be able to just revert that single commit where you removed them to get them back. |
||
pytest.raises(KeyError, self.index.get_loc, 0) | ||
assert self.index.get_loc(0.5) == 0 | ||
|
@@ -637,6 +639,7 @@ def test_get_loc_value(self): | |
idx = IntervalIndex.from_arrays([0, 2], [1, 3]) | ||
pytest.raises(KeyError, idx.get_loc, 1.5) | ||
|
||
# To be removed (see #16316, #16386) | ||
def slice_locs_cases(self, breaks): | ||
# TODO: same tests for more index types | ||
index = IntervalIndex.from_breaks([0, 1, 2], closed='right') | ||
|
@@ -665,12 +668,15 @@ def slice_locs_cases(self, breaks): | |
assert index.slice_locs(1, 1) == (0, 1) | ||
assert index.slice_locs(1, 2) == (0, 2) | ||
|
||
# To be removed (see #16316, #16386) | ||
def test_slice_locs_int64(self): | ||
self.slice_locs_cases([0, 1, 2]) | ||
|
||
# To be removed (see #16316, #16386) | ||
def test_slice_locs_float64(self): | ||
self.slice_locs_cases([0.0, 1.0, 2.0]) | ||
|
||
# To be removed (see #16316, #16386) | ||
def slice_locs_decreasing_cases(self, tuples): | ||
index = IntervalIndex.from_tuples(tuples) | ||
assert index.slice_locs(1.5, 0.5) == (1, 3) | ||
|
@@ -684,17 +690,21 @@ def slice_locs_decreasing_cases(self, tuples): | |
slice_locs = index.slice_locs(-1, -1) | ||
assert slice_locs[0] == slice_locs[1] | ||
|
||
# To be removed (see #16316, #16386) | ||
def test_slice_locs_decreasing_int64(self): | ||
self.slice_locs_cases([(2, 4), (1, 3), (0, 2)]) | ||
|
||
# To be removed (see #16316, #16386) | ||
def test_slice_locs_decreasing_float64(self): | ||
self.slice_locs_cases([(2., 4.), (1., 3.), (0., 2.)]) | ||
|
||
# To be removed (see #16316, #16386) | ||
def test_slice_locs_fails(self): | ||
index = IntervalIndex.from_tuples([(1, 2), (0, 1), (2, 3)]) | ||
with pytest.raises(KeyError): | ||
index.slice_locs(1, 2) | ||
|
||
# To be removed (see #16316, #16386) | ||
def test_get_loc_interval(self): | ||
assert self.index.get_loc(Interval(0, 1)) == 0 | ||
assert self.index.get_loc(Interval(0, 0.5)) == 0 | ||
|
@@ -703,6 +713,7 @@ def test_get_loc_interval(self): | |
pytest.raises(KeyError, self.index.get_loc, | ||
Interval(-1, 0, 'left')) | ||
|
||
# To be removed (see #16316, #16386) | ||
def test_get_indexer(self): | ||
actual = self.index.get_indexer([-1, 0, 0.5, 1, 1.5, 2, 3]) | ||
expected = np.array([-1, -1, 0, 0, 1, 1, -1], dtype='intp') | ||
|
@@ -725,6 +736,7 @@ def test_get_indexer(self): | |
expected = np.array([-1, 1], dtype='intp') | ||
tm.assert_numpy_array_equal(actual, expected) | ||
|
||
# To be removed (see #16316, #16386) | ||
def test_get_indexer_subintervals(self): | ||
|
||
# TODO: is this right? | ||
|
@@ -748,6 +760,7 @@ def test_get_indexer_subintervals(self): | |
expected = np.array([0, 0, 0], dtype='intp') | ||
tm.assert_numpy_array_equal(actual, expected) | ||
|
||
# To be removed (see #16316, #16386) | ||
def test_contains(self): | ||
# Only endpoints are valid. | ||
i = IntervalIndex.from_arrays([0, 1], [1, 2]) | ||
|
@@ -764,6 +777,7 @@ def test_contains(self): | |
assert Interval(3, 5) not in i | ||
assert Interval(-1, 0, closed='left') not in i | ||
|
||
# To be removed (see #16316, #16386) | ||
def testcontains(self): | ||
# can select values that are IN the range of a value | ||
i = IntervalIndex.from_arrays([0, 1], [1, 2]) | ||
|
@@ -795,7 +809,8 @@ def test_dropna(self, closed): | |
result = ii.dropna() | ||
tm.assert_index_equal(result, expected) | ||
|
||
def test_non_contiguous(self, closed): | ||
# TODO: check this behavior is consistent | ||
def test_non_contiguous(self): | ||
index = IntervalIndex.from_tuples([(0, 1), (2, 3)], closed=closed) | ||
target = [0.5, 1.5, 2.5] | ||
actual = index.get_indexer(target) | ||
|
@@ -1392,7 +1407,6 @@ def test_errors(self): | |
with tm.assert_raises_regex(TypeError, msg): | ||
interval_range(start=start, end=end) | ||
|
||
|
||
class TestIntervalTree(object): | ||
def setup_method(self, method): | ||
gentree = lambda dtype: IntervalTree(np.arange(5, dtype=dtype), | ||
|
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.
What do you mean by this?
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.
these comments are ok