Exemple #1
0
 def test_get_loc_closed(self, closed):
     tree = IntervalTree([0], [1], closed=closed)
     for p, errors in [(0, tree.open_left), (1, tree.open_right)]:
         if errors:
             with pytest.raises(KeyError):
                 tree.get_loc(p)
         else:
             tm.assert_numpy_array_equal(tree.get_loc(p),
                                         np.array([0], dtype='int64'))
Exemple #2
0
 def test_get_loc_closed(self):
     for closed in ['left', 'right', 'both', 'neither']:
         tree = IntervalTree([0], [1], closed=closed)
         for p, errors in [(0, tree.open_left), (1, tree.open_right)]:
             if errors:
                 with self.assertRaises(KeyError):
                     tree.get_loc(p)
             else:
                 self.assert_numpy_array_equal(tree.get_loc(p),
                                               np.array([0], dtype='int64'))
Exemple #3
0
 def test_get_loc_closed(self, closed):
     tree = IntervalTree([0], [1], closed=closed)
     for p, errors in [(0, tree.open_left), (1, tree.open_right)]:
         if errors:
             with pytest.raises(KeyError, match=str(p)):
                 tree.get_loc(p)
         else:
             result = tree.get_loc(p)
             expected = np.array([0], dtype="intp")
             tm.assert_numpy_array_equal(result, expected)
 def test_get_loc_closed(self, closed):
     tree = IntervalTree([0], [1], closed=closed)
     for p, errors in [(0, tree.open_left),
                       (1, tree.open_right)]:
         if errors:
             with pytest.raises(KeyError):
                 tree.get_loc(p)
         else:
             tm.assert_numpy_array_equal(tree.get_loc(p),
                                         np.array([0], dtype='int64'))
    def test_duplicates(self):
        tree = IntervalTree([0, 0, 0], [1, 1, 1])
        tm.assert_numpy_array_equal(np.sort(tree.get_loc(0.5)),
                                    np.array([0, 1, 2], dtype='int64'))

        with pytest.raises(KeyError):
            tree.get_indexer(np.array([0.5]))

        indexer, missing = tree.get_indexer_non_unique(np.array([0.5]))
        tm.assert_numpy_array_equal(np.sort(indexer),
                                    np.array([0, 1, 2], dtype='int64'))
        tm.assert_numpy_array_equal(missing, np.array([], dtype='int64'))
Exemple #6
0
    def test_duplicates(self):
        tree = IntervalTree([0, 0, 0], [1, 1, 1])
        tm.assert_numpy_array_equal(np.sort(tree.get_loc(0.5)),
                                    np.array([0, 1, 2], dtype='int64'))

        with pytest.raises(KeyError):
            tree.get_indexer(np.array([0.5]))

        indexer, missing = tree.get_indexer_non_unique(np.array([0.5]))
        tm.assert_numpy_array_equal(np.sort(indexer),
                                    np.array([0, 1, 2], dtype='int64'))
        tm.assert_numpy_array_equal(missing, np.array([], dtype='int64'))
    def test_duplicates(self, dtype):
        left = np.array([0, 0, 0], dtype=dtype)
        tree = IntervalTree(left, left + 1)

        result = np.sort(tree.get_loc(0.5))
        expected = np.array([0, 1, 2], dtype='intp')
        tm.assert_numpy_array_equal(result, expected)

        with pytest.raises(KeyError):
            tree.get_indexer(np.array([0.5]))

        indexer, missing = tree.get_indexer_non_unique(np.array([0.5]))
        result = np.sort(indexer)
        expected = np.array([0, 1, 2], dtype='intp')
        tm.assert_numpy_array_equal(result, expected)

        result = missing
        expected = np.array([], dtype='intp')
        tm.assert_numpy_array_equal(result, expected)
    def test_duplicates(self, dtype):
        left = np.array([0, 0, 0], dtype=dtype)
        tree = IntervalTree(left, left + 1)

        result = np.sort(tree.get_loc(0.5))
        expected = np.array([0, 1, 2], dtype='intp')
        tm.assert_numpy_array_equal(result, expected)

        with pytest.raises(KeyError):
            tree.get_indexer(np.array([0.5]))

        indexer, missing = tree.get_indexer_non_unique(np.array([0.5]))
        result = np.sort(indexer)
        expected = np.array([0, 1, 2], dtype='intp')
        tm.assert_numpy_array_equal(result, expected)

        result = missing
        expected = np.array([], dtype='intp')
        tm.assert_numpy_array_equal(result, expected)