|
2 | 2 | The tests in this package are to ensure the proper resultant dtypes of
|
3 | 3 | set operations.
|
4 | 4 | '''
|
| 5 | +from collections import OrderedDict |
5 | 6 | import itertools as it
|
6 | 7 |
|
7 | 8 | import numpy as np
|
|
10 | 11 | from pandas.core.dtypes.common import is_dtype_equal
|
11 | 12 |
|
12 | 13 | import pandas as pd
|
13 |
| -from pandas import Int64Index, RangeIndex |
| 14 | +from pandas import Float64Index, Int64Index, RangeIndex, UInt64Index |
| 15 | +from pandas.api.types import pandas_dtype |
14 | 16 | from pandas.tests.indexes.conftest import indices_list
|
15 | 17 | import pandas.util.testing as tm
|
16 | 18 |
|
17 |
| -COMPATIBLE_INCONSISTENT_PAIRS = { |
18 |
| - (Int64Index, RangeIndex): (tm.makeIntIndex, tm.makeRangeIndex) |
19 |
| -} |
| 19 | +COMPATIBLE_INCONSISTENT_PAIRS = OrderedDict([ |
| 20 | + ((Int64Index, RangeIndex), (tm.makeIntIndex, tm.makeRangeIndex)), |
| 21 | + ((Float64Index, Int64Index), (tm.makeFloatIndex, tm.makeIntIndex)), |
| 22 | + ((Float64Index, RangeIndex), (tm.makeFloatIndex, tm.makeIntIndex)), |
| 23 | + ((Float64Index, UInt64Index), (tm.makeFloatIndex, tm.makeUIntIndex)), |
| 24 | +]) |
20 | 25 |
|
21 | 26 |
|
22 | 27 | @pytest.fixture(params=list(it.combinations(indices_list, 2)),
|
@@ -74,3 +79,29 @@ def test_compatible_inconsistent_pairs(idx_fact1, idx_fact2):
|
74 | 79 |
|
75 | 80 | assert res1.dtype in (idx1.dtype, idx2.dtype)
|
76 | 81 | assert res2.dtype in (idx1.dtype, idx2.dtype)
|
| 82 | + |
| 83 | + |
| 84 | +@pytest.mark.parametrize('left, right, expected', [ |
| 85 | + ('int64', 'int64', 'int64'), |
| 86 | + ('int64', 'uint64', 'object'), |
| 87 | + ('int64', 'float64', 'float64'), |
| 88 | + ('uint64', 'float64', 'float64'), |
| 89 | + ('uint64', 'uint64', 'uint64'), |
| 90 | + ('float64', 'float64', 'float64'), |
| 91 | + ('datetime64[ns]', 'int64', 'object'), |
| 92 | + ('datetime64[ns]', 'uint64', 'object'), |
| 93 | + ('datetime64[ns]', 'float64', 'object'), |
| 94 | + ('datetime64[ns, CET]', 'int64', 'object'), |
| 95 | + ('datetime64[ns, CET]', 'uint64', 'object'), |
| 96 | + ('datetime64[ns, CET]', 'float64', 'object'), |
| 97 | + ('Period[D]', 'int64', 'object'), |
| 98 | + ('Period[D]', 'uint64', 'object'), |
| 99 | + ('Period[D]', 'float64', 'object'), |
| 100 | +]) |
| 101 | +def test_union_dtypes(left, right, expected): |
| 102 | + left = pandas_dtype(left) |
| 103 | + right = pandas_dtype(right) |
| 104 | + a = pd.Index([], dtype=left) |
| 105 | + b = pd.Index([], dtype=right) |
| 106 | + result = (a | b).dtype |
| 107 | + assert result == expected |
0 commit comments