-
- Notifications
You must be signed in to change notification settings - Fork 19.3k
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 1 commit
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
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -570,7 +570,6 @@ def slice_locs_with_interval_updated_behavior(self): | |
| assert index.slice_locs(end=Interval(0, 2)) == () | ||
| assert index.slice_locs(start=Interval(2, 4), end=Interval(0, 2)) == () | ||
| | ||
| | ||
| @pytest.mark.xfail(reason="new indexing tests for issue 16316") | ||
| def slice_locs_with_ints_and_floats_updated_behavior(self): | ||
| | ||
| | @@ -654,187 +653,79 @@ def get_indexer_for_interval_updated_behavior(self): | |
| index = IntervalIndex.from_tuples([(0, 2.5), (1, 3), (2, 4)], closed='right') | ||
| | ||
| # single queries | ||
| result = index.get_indexer([Interval(1, 3, closed='right')]) | ||
| expected = np.array([1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([Interval(1, 3, closed='left')]) | ||
| expected = np.array([-1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([Interval(1, 3, closed='both')]) | ||
| expected = np.array([-1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([Interval(1, 3, closed='neither')]) | ||
| expected = np.array([-1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([Interval(1, 4, closed='right')]) | ||
| expected = np.array([-1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([Interval(0, 4, closed='right')]) | ||
| expected = np.array([-1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([Interval(1, 2, closed='right')]) | ||
| expected = np.array([-1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| queries = [ Interval(1, 3, closed='right'), | ||
| Interval(1, 3, closed='left'), | ||
| Interval(1, 3, closed='both'), | ||
| Interval(1, 3, closed='neither'), | ||
| Interval(1, 4, closed='right'), | ||
| Interval(0, 4, closed='right'), | ||
| Interval(1, 2, closed='right') ] | ||
| expected = [1, -1, -1, -1, -1, -1, -1] | ||
| | ||
| for query, expected_result in zip(queries, expected): | ||
| result = index.get_indexer([query]) | ||
| expect = np.array([expected_result], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expect) | ||
| | ||
| # multiple queries | ||
| result = index.get_indexer([Interval(2, 4, closed='right'), | ||
| Interval(1, 3, closed='right') ]) | ||
| expected = np.array([2, 1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([Interval(1, 3, closed='right'), | ||
| Interval(0, 2, closed='right') ]) | ||
| expected = np.array([1, -1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| queries = [ | ||
| [Interval(2, 4, closed='right'), Interval(1, 3, closed='right')], | ||
| [Interval(1, 3, closed='right'), Interval(0, 2, closed='right')], | ||
| [Interval(1, 3, closed='right'), Interval(1, 3, closed='left')], | ||
| index ] | ||
| expected = [[2, 1], [1, -1], [1, -1], [0, 1, 2]] | ||
| | ||
| result = index.get_indexer([Interval(1, 3, closed='right'), | ||
| Interval(1, 3, closed='left') ]) | ||
| expected = np.array([1, -1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| for query, expected_result in zip(queries, expected): | ||
| result = index.get_indexer(query) | ||
| expect = np.array(expected_result, dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expect) | ||
| | ||
| result = index.get_indexer(index) | ||
| expected = np.array([0, 1, 2], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| @pytest.mark.xfail(reason="new indexing tests for issue 16316") | ||
| def get_indexer_for_ints_and_floats_updated_behavior(self): | ||
| | ||
| ||
| index = IntervalIndex.from_tuples([(0, 1), (1, 2), (3, 4)], closed='right') | ||
| | ||
| # single queries | ||
| result = index.get_indexer([-0.5]) | ||
| expected = np.array([-1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([0]) | ||
| expected = np.array([-1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([0.5]) | ||
| expected = np.array([0], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([1]) | ||
| expected = np.array([0], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([1.5]) | ||
| expected = np.array([1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([2]) | ||
| expected = np.array([1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([2.5]) | ||
| expected = np.array([-1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([3]) | ||
| expected = np.array([-1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| queries = [-0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5] | ||
| expected = [-1, -1, 0, 0, 1, 1, -1, -1, 2, 2, -1] | ||
| | ||
| result = index.get_indexer([3.5]) | ||
| expected = np.array([2], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([4]) | ||
| expected = np.array([2], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([4.5]) | ||
| expected = np.array([-1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| for query, expected_result in zip(queries, expected): | ||
| result = index.get_indexer([query]) | ||
| expect = np.array([expected_result], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expect) | ||
| | ||
| # multiple queries | ||
| result = index.get_indexer([1, 2]) | ||
| expected = np.array([0, 1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([1, 2, 3]) | ||
| expected = np.array([0, 1, -1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer([1, 2, 3, 4]) | ||
| expected = np.array([0, 1, -1, 2], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| queries = [[1, 2],[1, 2, 3],[1, 2, 3, 4],[1, 2, 3, 4, 2]] | ||
| expected = [[0, 1], [0, 1, -1], [0, 1, -1, 2], [0, 1, -1, 2, 1]] | ||
| | ||
| result = index.get_indexer([1, 2, 3, 4, 2]) | ||
| expected = np.array([0, 1, -1, 2, 1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| for query, expected_result in zip(queries, expected): | ||
| result = index.get_indexer(query) | ||
| expect = np.array(expected_result, dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expect) | ||
| | ||
| ||
| @pytest.mark.xfail(reason="new indexing tests for issue 16316") | ||
| def get_indexer_nonunique_for_ints_and_floats_updated_behavior(self): | ||
| | ||
| index = IntervalIndex.from_tuples([(0, 2.5), (1, 3), (2, 4)], closed='left') | ||
| | ||
| # single queries | ||
| result = index.get_indexer_nonunique([-0.5]) | ||
| expected = np.array([-1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer_nonunique([0]) | ||
| expected = np.array([0], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer_nonunique([0.5]) | ||
| expected = np.array([0], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer_nonunique([1]) | ||
| expected = np.array([0, 1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer_nonunique([1.5]) | ||
| expected = np.array([0, 1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| queries = [-0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5] | ||
| expected = [[-1], [0], [0], [0, 1], [0, 1], [0, 1, 2], [1, 2], [2], [2], [-1], [-1]] | ||
| | ||
| result = index.get_indexer_nonunique([2]) | ||
| expected = np.array([0, 1, 2], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| for query, expected_result in zip(queries, expected): | ||
| result = index.get_indexer_nonunique([query]) | ||
| ||
| expect = np.array(expected_result, dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expect) | ||
| | ||
| result = index.get_indexer_nonunique([2.5]) | ||
| expected = np.array([1, 2], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer_nonunique([3]) | ||
| expected = np.array([2], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer_nonunique([3.5]) | ||
| expected = np.array([2], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer_nonunique([4]) | ||
| expected = np.array([-1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer_nonunique([4.5]) | ||
| expected = np.array([-1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| queries = [[1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 2]] | ||
| expected = [[0, 1, 0, 1, 2], [0, 1, 0, 1, 2, 2], [0, 1, 0, 1, 2, 2, -1], [0, 1, 0, 1, 2, 2, -1, 0, 1, 2]] # should we use tuples here? | ||
| | ||
| # multiple queries | ||
| result = index.get_indexer_nonunique([1, 2]) | ||
| expected = np.array([0, 1, 0, 1, 2], dtype='intp') # maybe we could put these in tuples? [(0, 1), (0, 1, 2)] | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer_nonunique([1, 2, 3]) | ||
| expected = np.array([0, 1, 0, 1, 2, 2], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer_nonunique([1, 2, 3, 4]) | ||
| expected = np.array([0, 1, 0, 1, 2, 2, -1], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| | ||
| result = index.get_indexer_nonunique([1, 2, 3, 4, 2]) | ||
| expected = np.array([0, 1, 0, 1, 2, 2, -1, 0, 1, 2], dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expected) | ||
| for query, expected_result in zip(queries, expected): | ||
| result = index.get_indexer_nonunique(query) | ||
| expect = np.array(expected_result, dtype='intp') | ||
| tm.assert_numpy_array_equal(result, expect) | ||
| | ||
| # we may also want to test get_indexer for the case when | ||
| # the intervals are duplicated, decreasing, non-monotonic, etc.. | ||
| | ||
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.
same