|
3 | 3 | import numpy as np
|
4 | 4 | import pytest
|
5 | 5 |
|
6 |
| -from pandas import Index, Int64Index, RangeIndex |
| 6 | +from pandas import Index, Int64Index, RangeIndex, UInt64Index |
7 | 7 | import pandas._testing as tm
|
8 | 8 |
|
9 | 9 |
|
10 | 10 | class TestRangeIndexSetOps:
|
| 11 | + @pytest.mark.parametrize("klass", [RangeIndex, Int64Index, UInt64Index]) |
| 12 | + def test_intersection_mismatched_dtype(self, klass): |
| 13 | + # check that we cast to float, not object |
| 14 | + index = RangeIndex(start=0, stop=20, step=2, name="foo") |
| 15 | + index = klass(index) |
| 16 | + |
| 17 | + flt = index.astype(np.float64) |
| 18 | + |
| 19 | + # bc index.equals(flt), we go through fastpath and get RangeIndex back |
| 20 | + result = index.intersection(flt) |
| 21 | + tm.assert_index_equal(result, index, exact=True) |
| 22 | + |
| 23 | + result = flt.intersection(index) |
| 24 | + tm.assert_index_equal(result, flt, exact=True) |
| 25 | + |
| 26 | + # neither empty, not-equals |
| 27 | + result = index.intersection(flt[1:]) |
| 28 | + tm.assert_index_equal(result, flt[1:], exact=True) |
| 29 | + |
| 30 | + result = flt[1:].intersection(index) |
| 31 | + tm.assert_index_equal(result, flt[1:], exact=True) |
| 32 | + |
| 33 | + # empty other |
| 34 | + result = index.intersection(flt[:0]) |
| 35 | + tm.assert_index_equal(result, flt[:0], exact=True) |
| 36 | + |
| 37 | + result = flt[:0].intersection(index) |
| 38 | + tm.assert_index_equal(result, flt[:0], exact=True) |
| 39 | + |
11 | 40 | def test_intersection(self, sort):
|
12 | 41 | # intersect with Int64Index
|
13 | 42 | index = RangeIndex(start=0, stop=20, step=2)
|
|
0 commit comments