Skip to content

Commit 2bea731

Browse files
committed
TST: Added object array and NaT tests, moved to test_indexing (pandas-dev#35498)
1 parent e6a00aa commit 2bea731

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

pandas/tests/indexes/test_base.py

-19
Original file line numberDiff line numberDiff line change
@@ -2614,22 +2614,3 @@ def construct(dtype):
26142614
no_matches = np.array([-1] * 6, dtype=np.intp)
26152615
tm.assert_numpy_array_equal(result[0], no_matches)
26162616
tm.assert_numpy_array_equal(result[1], no_matches)
2617-
2618-
2619-
@pytest.mark.parametrize(
2620-
"idx, target, expected",
2621-
[
2622-
([np.nan, "var1", np.nan], [np.nan], np.array([0, 2], dtype=np.int64)),
2623-
(
2624-
[np.nan, "var1", np.nan],
2625-
[np.nan, "var1"],
2626-
np.array([0, 2, 1], dtype=np.int64),
2627-
),
2628-
],
2629-
)
2630-
def test_get_indexer_non_unique_multiple_nans(idx, target, expected):
2631-
# GH 35392
2632-
axis = pd.Index(idx)
2633-
actual = axis.get_indexer_for(target)
2634-
2635-
tm.assert_numpy_array_equal(actual, expected)

pandas/tests/indexes/test_indexing.py

+32-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
take
88
where
99
get_indexer
10+
get_indexer_for
1011
slice_locs
1112
asof_locs
1213
@@ -16,7 +17,9 @@
1617
import numpy as np
1718
import pytest
1819

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
2023
import pandas._testing as tm
2124

2225

@@ -96,3 +99,31 @@ def test_getitem_deprecated_float(idx):
9699

97100
expected = idx[1]
98101
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

Comments
 (0)