Exemplo n.º 1
0
 def test_convert_unsorted_datetime_index_raises(self):
     index = pd.to_datetime(['2001', '2000', '2002'])
     with pytest.raises(KeyError):
         # pandas will try to convert this into an array indexer. We should
         # raise instead, so we can be sure the result of indexing with a
         # slice is always a view.
         indexing.convert_label_indexer(index, slice('2001', '2002'))
Exemplo n.º 2
0
 def test_convert_unsorted_datetime_index_raises(self):
     index = pd.to_datetime(['2001', '2000', '2002'])
     with pytest.raises(KeyError):
         # pandas will try to convert this into an array indexer. We should
         # raise instead, so we can be sure the result of indexing with a
         # slice is always a view.
         indexing.convert_label_indexer(index, slice('2001', '2002'))
Exemplo n.º 3
0
 def test_convert_label_indexer(self):
     # TODO: add tests that aren't just for edge cases
     index = pd.Index([1, 2, 3])
     with self.assertRaisesRegexp(KeyError, 'not all values found'):
         indexing.convert_label_indexer(index, [0])
     with self.assertRaises(KeyError):
         indexing.convert_label_indexer(index, 0)
Exemplo n.º 4
0
    def test_convert_label_indexer_datetime(self):
        index = pd.to_datetime(["2000-01-01", "2001-01-01", "2002-01-01"])
        actual = indexing.convert_label_indexer(index, "2001-01-01")
        expected = (1, None)
        assert actual == expected

        actual = indexing.convert_label_indexer(index, index.to_numpy()[1])
        assert actual == expected
Exemplo n.º 5
0
    def test_convert_label_indexer(self):
        # TODO: add tests that aren't just for edge cases
        index = pd.Index([1, 2, 3])
        with raises_regex(KeyError, 'not all values found'):
            indexing.convert_label_indexer(index, [0])
        with pytest.raises(KeyError):
            indexing.convert_label_indexer(index, 0)
        with raises_regex(ValueError, 'does not have a MultiIndex'):
            indexing.convert_label_indexer(index, {'one': 0})

        mindex = pd.MultiIndex.from_product([['a', 'b'], [1, 2]],
                                            names=('one', 'two'))
        with raises_regex(KeyError, 'not all values found'):
            indexing.convert_label_indexer(mindex, [0])
        with pytest.raises(KeyError):
            indexing.convert_label_indexer(mindex, 0)
        with pytest.raises(ValueError):
            indexing.convert_label_indexer(index, {'three': 0})
        with pytest.raises((KeyError, IndexError)):
            # pandas 0.21 changed this from KeyError to IndexError
            indexing.convert_label_indexer(mindex,
                                           (slice(None), 1, 'no_level'))
Exemplo n.º 6
0
    def test_convert_label_indexer(self):
        # TODO: add tests that aren't just for edge cases
        index = pd.Index([1, 2, 3])
        with raises_regex(KeyError, 'not all values found'):
            indexing.convert_label_indexer(index, [0])
        with pytest.raises(KeyError):
            indexing.convert_label_indexer(index, 0)
        with raises_regex(ValueError, 'does not have a MultiIndex'):
            indexing.convert_label_indexer(index, {'one': 0})

        mindex = pd.MultiIndex.from_product([['a', 'b'], [1, 2]],
                                            names=('one', 'two'))
        with raises_regex(KeyError, 'not all values found'):
            indexing.convert_label_indexer(mindex, [0])
        with pytest.raises(KeyError):
            indexing.convert_label_indexer(mindex, 0)
        with pytest.raises(ValueError):
            indexing.convert_label_indexer(index, {'three': 0})
        with pytest.raises((KeyError, IndexError)):
            # pandas 0.21 changed this from KeyError to IndexError
            indexing.convert_label_indexer(
                mindex, (slice(None), 1, 'no_level'))
Exemplo n.º 7
0
    def test_convert_label_indexer(self):
        # TODO: add tests that aren't just for edge cases
        index = pd.Index([1, 2, 3])
        with self.assertRaisesRegexp(KeyError, 'not all values found'):
            indexing.convert_label_indexer(index, [0])
        with self.assertRaises(KeyError):
            indexing.convert_label_indexer(index, 0)
        with self.assertRaisesRegexp(ValueError, 'does not have a MultiIndex'):
            indexing.convert_label_indexer(index, {'one': 0})

        mindex = pd.MultiIndex.from_product([['a', 'b'], [1, 2]],
                                            names=('one', 'two'))
        with self.assertRaisesRegexp(KeyError, 'not all values found'):
            indexing.convert_label_indexer(mindex, [0])
        with self.assertRaises(KeyError):
            indexing.convert_label_indexer(mindex, 0)
        with self.assertRaises(ValueError):
            indexing.convert_label_indexer(index, {'three': 0})
        with self.assertRaisesRegexp(KeyError, 'index to be fully lexsorted'):
            indexing.convert_label_indexer(mindex,
                                           (slice(None), 1, 'no_level'))
Exemplo n.º 8
0
    def test_convert_label_indexer(self):
        # TODO: add tests that aren't just for edge cases
        index = pd.Index([1, 2, 3])
        with raises_regex(KeyError, "not all values found"):
            indexing.convert_label_indexer(index, [0])
        with pytest.raises(KeyError):
            indexing.convert_label_indexer(index, 0)
        with raises_regex(ValueError, "does not have a MultiIndex"):
            indexing.convert_label_indexer(index, {"one": 0})

        mindex = pd.MultiIndex.from_product([["a", "b"], [1, 2]],
                                            names=("one", "two"))
        with raises_regex(KeyError, "not all values found"):
            indexing.convert_label_indexer(mindex, [0])
        with pytest.raises(KeyError):
            indexing.convert_label_indexer(mindex, 0)
        with pytest.raises(ValueError):
            indexing.convert_label_indexer(index, {"three": 0})
        with pytest.raises((KeyError, IndexError)):
            # pandas 0.21 changed this from KeyError to IndexError
            indexing.convert_label_indexer(mindex,
                                           (slice(None), 1, "no_level"))
Exemplo n.º 9
0
    def test_convert_label_indexer(self):
        # TODO: add tests that aren't just for edge cases
        index = pd.Index([1, 2, 3])
        with self.assertRaisesRegexp(KeyError, 'not all values found'):
            indexing.convert_label_indexer(index, [0])
        with self.assertRaises(KeyError):
            indexing.convert_label_indexer(index, 0)
        with self.assertRaisesRegexp(ValueError, 'does not have a MultiIndex'):
            indexing.convert_label_indexer(index, {'one': 0})

        mindex = pd.MultiIndex.from_product([['a', 'b'], [1, 2]],
                                            names=('one', 'two'))
        with self.assertRaisesRegexp(KeyError, 'not all values found'):
            indexing.convert_label_indexer(mindex, [0])
        with self.assertRaises(KeyError):
            indexing.convert_label_indexer(mindex, 0)
        with self.assertRaises(ValueError):
            indexing.convert_label_indexer(index, {'three': 0})
        with self.assertRaisesRegexp(KeyError, 'index to be fully lexsorted'):
            indexing.convert_label_indexer(mindex, (slice(None), 1, 'no_level'))
Exemplo n.º 10
0
    def test_convert_label_indexer(self):
        # TODO: add tests that aren't just for edge cases
        index = pd.Index([1, 2, 3])
        with self.assertRaisesRegexp(KeyError, "not all values found"):
            indexing.convert_label_indexer(index, [0])
        with self.assertRaises(KeyError):
            indexing.convert_label_indexer(index, 0)
        with self.assertRaisesRegexp(ValueError, "does not have a MultiIndex"):
            indexing.convert_label_indexer(index, {"one": 0})

        mindex = pd.MultiIndex.from_product([["a", "b"], [1, 2]], names=("one", "two"))
        with self.assertRaisesRegexp(KeyError, "not all values found"):
            indexing.convert_label_indexer(mindex, [0])
        with self.assertRaises(KeyError):
            indexing.convert_label_indexer(mindex, 0)
        with self.assertRaises(ValueError):
            indexing.convert_label_indexer(index, {"three": 0})
        with self.assertRaisesRegexp(KeyError, "index to be fully lexsorted"):
            indexing.convert_label_indexer(mindex, (slice(None), 1, "no_level"))