|
7 | 7 | take
|
8 | 8 | where
|
9 | 9 | get_indexer
|
| 10 | + get_indexer_for |
10 | 11 | slice_locs
|
11 | 12 | asof_locs
|
12 | 13 |
|
|
16 | 17 | import numpy as np
|
17 | 18 | import pytest
|
18 | 19 |
|
19 |
| -from pandas import Float64Index, Index, Int64Index, UInt64Index |
| 20 | +from pandas._libs.tslibs import NaT |
| 21 | + |
| 22 | +from pandas import DatetimeIndex, Float64Index, Index, Int64Index, UInt64Index |
20 | 23 | import pandas._testing as tm
|
21 | 24 |
|
22 | 25 |
|
@@ -96,3 +99,31 @@ def test_getitem_deprecated_float(idx):
|
96 | 99 |
|
97 | 100 | expected = idx[1]
|
98 | 101 | assert result == expected
|
| 102 | + |
| 103 | + |
| 104 | +@pytest.mark.parametrize( |
| 105 | + "idx, target, expected", |
| 106 | + [ |
| 107 | + ([np.nan, "var1", np.nan], [np.nan], np.array([0, 2], dtype=np.int64)), |
| 108 | + ( |
| 109 | + [np.nan, "var1", np.nan], |
| 110 | + [np.nan, "var1"], |
| 111 | + np.array([0, 2, 1], dtype=np.int64), |
| 112 | + ), |
| 113 | + ( |
| 114 | + np.array([np.nan, "var1", np.nan], dtype=np.object), |
| 115 | + [np.nan], |
| 116 | + np.array([0, 2], dtype=np.int64), |
| 117 | + ), |
| 118 | + ( |
| 119 | + DatetimeIndex(["2020-08-05", NaT, NaT]), |
| 120 | + [NaT], |
| 121 | + np.array([1, 2], dtype=np.int64), |
| 122 | + ), |
| 123 | + ], |
| 124 | +) |
| 125 | +def test_get_indexer_non_unique_multiple_nans(idx, target, expected): |
| 126 | + # GH 35392 |
| 127 | + axis = Index(idx) |
| 128 | + actual = axis.get_indexer_for(target) |
| 129 | + tm.assert_numpy_array_equal(actual, expected) |
0 commit comments