Skip to content

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

Merged
merged 63 commits into from
Dec 28, 2017
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
18c76f4
new interval and intervalIndex behavior spec
May 18, 2017
ddc508c
moved tests from indexing to indexes, and added new tests
May 25, 2017
a1c3e7a
first pass at @shoyer's review
May 26, 2017
557d701
quick update comments
May 26, 2017
7d28038
another quick pass
Jun 6, 2017
ff1fbf2
sanity check
Jun 6, 2017
aadfdcd
fixed one little issue.
Jun 7, 2017
c7f6fb8
fixed most of @jorisvandenbossche's review
Jun 19, 2017
1379b08
worked on 'contains'
Jun 19, 2017
80ebeb3
remove covers and overlaps -- to be added to a separate PR
Jun 19, 2017
fef3187
take back changes involving .contains() and __contains__
Jun 20, 2017
e3a12fa
some updates discussed
Jun 22, 2017
06a2835
quick thought...
Jun 22, 2017
08bd9e4
tiny update
Jun 29, 2017
6381744
An update to get_indexer behavior
Jul 6, 2017
b346af7
update slice locs behavior
Jul 6, 2017
ccd23aa
remove tests flagged for removal.
Jul 14, 2017
ac818f9
left side of interval must be <= right side
Jul 17, 2017
4a10007
move to throwing errors for slice locs with overlapping stuff
Jul 17, 2017
e549c3d
compress test cases
Jul 17, 2017
d5a8287
Change to InvalidIndexError
Jul 17, 2017
0e50729
compressing tests even more
Jul 17, 2017
2c953b6
some lint issues
Jul 17, 2017
08d315c
I believe all the test cases are complete.
Jul 18, 2017
9f905a8
autopep
Jul 18, 2017
e1eeb59
more pep8
Jul 18, 2017
4c54f33
remove some stuff
Jul 18, 2017
ca04cb2
tiny update
Jul 18, 2017
bfaefef
update get_indexer_non_unique tests
Jul 26, 2017
ce5074a
autopep
Jul 26, 2017
4c5496e
hopefully this is valid python
Aug 3, 2017
33938d6
Merge remote-tracking branch 'pandas-dev/master'
Sep 15, 2017
7f4c5e5
a couple updates, and a bug fix
Sep 15, 2017
0aaaddf
oops
Sep 15, 2017
a44c926
fix some lint issues
Sep 15, 2017
4cef040
start working on the review
Sep 15, 2017
66486d0
fix some slice-locs stuff
Sep 16, 2017
c0dfef8
lint issues mostly
Sep 16, 2017
5301dd5
try to satisfy pep
Sep 16, 2017
57c9ba7
for some reason that didn't make PEP happy
Sep 16, 2017
4cbbf2d
pep
Sep 16, 2017
6126662
parameterize and add a couple comments.
Sep 25, 2017
dc00af6
hopefully this works.
Sep 26, 2017
604d48d
Merge remote-tracking branch 'pandas-dev/master'
Sep 26, 2017
10c9177
fix merge conflicts
Sep 26, 2017
c8be3e6
parametrize a little bit more
jorisvandenbossche Sep 29, 2017
93f1742
remove _updated_behaviour from test name + PEP8 (unused imports)
jorisvandenbossche Sep 29, 2017
3464883
update loc tests
jorisvandenbossche Sep 30, 2017
06484f5
Merge branch 'master' into master
alexlenail Dec 19, 2017
e82ae33
update comments
Dec 20, 2017
6834c9a
Merge remote-tracking branch 'origin/master'
Dec 20, 2017
33ebe1b
worked on parameterization
Dec 20, 2017
be050d6
move xfails to top of module
Dec 21, 2017
1cc8004
minor update for pep
Dec 21, 2017
930da2b
more for pep
Dec 21, 2017
2e01d28
fix mistake
Dec 21, 2017
5c000a0
might have messed up a function signature during a previous merge. Se…
Dec 22, 2017
96c978a
formatting, potentially last bug
Dec 22, 2017
ae03d01
Merge branch 'master' into PR_TOOL_MERGE_PR_16386
jreback Dec 23, 2017
518d16e
skip interval_new tests
jreback Dec 23, 2017
f530637
lint
jreback Dec 23, 2017
d90d310
Merge branch 'master' into PR_TOOL_MERGE_PR_16386
jreback Dec 23, 2017
acefcb0
Merge branch 'master' into PR_TOOL_MERGE_PR_16386
jreback Dec 28, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions pandas/tests/indexes/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 with test_interval_new.py
def test_get_item(self, closed):
i = IntervalIndex.from_arrays((0, 1, np.nan), (1, 2, np.nan),
closed=closed)
Expand All @@ -615,6 +616,7 @@ def test_get_item(self, closed):
closed=closed)
tm.assert_index_equal(result, expected)

# To be removed, replaced by test_interval_new.py (see #16316, #16386)
def test_get_loc_value(self):
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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
Expand All @@ -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, replaced by test_interval_new.py (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')
Expand Down Expand Up @@ -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, replaced by test_interval_new.py (see #16316, #16386)
def test_slice_locs_int64(self):
self.slice_locs_cases([0, 1, 2])

# To be removed, replaced by test_interval_new.py (see #16316, #16386)
def test_slice_locs_float64(self):
self.slice_locs_cases([0.0, 1.0, 2.0])

# To be removed, replaced by test_interval_new.py (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)
Expand All @@ -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, replaced by test_interval_new.py (see #16316, #16386)
def test_slice_locs_decreasing_int64(self):
self.slice_locs_cases([(2, 4), (1, 3), (0, 2)])

# To be removed, replaced by test_interval_new.py (see #16316, #16386)
def test_slice_locs_decreasing_float64(self):
self.slice_locs_cases([(2., 4.), (1., 3.), (0., 2.)])

# To be removed, replaced by test_interval_new.py (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, replaced by test_interval_new.py (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
Expand All @@ -703,6 +713,7 @@ def test_get_loc_interval(self):
pytest.raises(KeyError, self.index.get_loc,
Interval(-1, 0, 'left'))

# 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])
expected = np.array([-1, -1, 0, 0, 1, 1, -1], dtype='intp')
Expand All @@ -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, replaced by test_interval_new.py (see #16316, #16386)
def test_get_indexer_subintervals(self):

# TODO: is this right?
Expand All @@ -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, 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])
Expand All @@ -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, replaced by test_interval_new.py (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])
Expand Down Expand Up @@ -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 with test_interval_new.py
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)
Expand Down Expand Up @@ -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),
Expand Down
Loading