|
| 1 | +from decimal import Decimal |
| 2 | + |
1 | 3 | import numpy as np
|
2 | 4 | import pytest
|
3 | 5 |
|
@@ -90,12 +92,63 @@ def test_get_indexer_non_unique_nas(self, nulls_fixture):
|
90 | 92 | # matching-but-not-identical nans
|
91 | 93 | if is_matching_na(nulls_fixture, float("NaN")):
|
92 | 94 | index = Index(["a", float("NaN"), "b", float("NaN")])
|
| 95 | + match_but_not_identical = True |
| 96 | + elif is_matching_na(nulls_fixture, Decimal("NaN")): |
| 97 | + index = Index(["a", Decimal("NaN"), "b", Decimal("NaN")]) |
| 98 | + match_but_not_identical = True |
| 99 | + else: |
| 100 | + match_but_not_identical = False |
| 101 | + |
| 102 | + if match_but_not_identical: |
93 | 103 | indexer, missing = index.get_indexer_non_unique([nulls_fixture])
|
94 | 104 |
|
95 | 105 | expected_indexer = np.array([1, 3], dtype=np.intp)
|
96 | 106 | tm.assert_numpy_array_equal(indexer, expected_indexer)
|
97 | 107 | tm.assert_numpy_array_equal(missing, expected_missing)
|
98 | 108 |
|
| 109 | + @pytest.mark.filterwarnings("ignore:elementwise comp:DeprecationWarning") |
| 110 | + def test_get_indexer_non_unique_np_nats(self, np_nat_fixture, np_nat_fixture2): |
| 111 | + expected_missing = np.array([], dtype=np.intp) |
| 112 | + # matching-but-not-identical nats |
| 113 | + if is_matching_na(np_nat_fixture, np_nat_fixture2): |
| 114 | + # ensure nats are different objects |
| 115 | + index = Index( |
| 116 | + np.array( |
| 117 | + ["2021-10-02", np_nat_fixture.copy(), np_nat_fixture2.copy()], |
| 118 | + dtype=object, |
| 119 | + ), |
| 120 | + dtype=object, |
| 121 | + ) |
| 122 | + # pass as index to prevent target from being casted to DatetimeIndex |
| 123 | + indexer, missing = index.get_indexer_non_unique( |
| 124 | + Index([np_nat_fixture], dtype=object) |
| 125 | + ) |
| 126 | + expected_indexer = np.array([1, 2], dtype=np.intp) |
| 127 | + tm.assert_numpy_array_equal(indexer, expected_indexer) |
| 128 | + tm.assert_numpy_array_equal(missing, expected_missing) |
| 129 | + # dt64nat vs td64nat |
| 130 | + else: |
| 131 | + index = Index( |
| 132 | + np.array( |
| 133 | + [ |
| 134 | + "2021-10-02", |
| 135 | + np_nat_fixture, |
| 136 | + np_nat_fixture2, |
| 137 | + np_nat_fixture, |
| 138 | + np_nat_fixture2, |
| 139 | + ], |
| 140 | + dtype=object, |
| 141 | + ), |
| 142 | + dtype=object, |
| 143 | + ) |
| 144 | + # pass as index to prevent target from being casted to DatetimeIndex |
| 145 | + indexer, missing = index.get_indexer_non_unique( |
| 146 | + Index([np_nat_fixture], dtype=object) |
| 147 | + ) |
| 148 | + expected_indexer = np.array([1, 3], dtype=np.intp) |
| 149 | + tm.assert_numpy_array_equal(indexer, expected_indexer) |
| 150 | + tm.assert_numpy_array_equal(missing, expected_missing) |
| 151 | + |
99 | 152 |
|
100 | 153 | class TestSliceLocs:
|
101 | 154 | @pytest.mark.parametrize(
|
|
0 commit comments