|
1 | 1 | import numpy as np
|
2 | 2 | import pytest
|
3 | 3 |
|
| 4 | +from pandas._libs.missing import is_matching_na |
| 5 | + |
4 | 6 | import pandas as pd
|
5 | 7 | from pandas import Index
|
6 | 8 | import pandas._testing as tm
|
@@ -66,6 +68,35 @@ def test_get_indexer_with_NA_values(
|
66 | 68 | tm.assert_numpy_array_equal(result, expected)
|
67 | 69 |
|
68 | 70 |
|
| 71 | +class TestGetIndexerNonUnique: |
| 72 | + def test_get_indexer_non_unique_nas(self, nulls_fixture): |
| 73 | + # even though this isn't non-unique, this should still work |
| 74 | + index = Index(["a", "b", nulls_fixture]) |
| 75 | + indexer, missing = index.get_indexer_non_unique([nulls_fixture]) |
| 76 | + |
| 77 | + expected_indexer = np.array([2], dtype=np.intp) |
| 78 | + expected_missing = np.array([], dtype=np.intp) |
| 79 | + tm.assert_numpy_array_equal(indexer, expected_indexer) |
| 80 | + tm.assert_numpy_array_equal(missing, expected_missing) |
| 81 | + |
| 82 | + # actually non-unique |
| 83 | + index = Index(["a", nulls_fixture, "b", nulls_fixture]) |
| 84 | + indexer, missing = index.get_indexer_non_unique([nulls_fixture]) |
| 85 | + |
| 86 | + expected_indexer = np.array([1, 3], dtype=np.intp) |
| 87 | + tm.assert_numpy_array_equal(indexer, expected_indexer) |
| 88 | + tm.assert_numpy_array_equal(missing, expected_missing) |
| 89 | + |
| 90 | + # matching-but-not-identical nans |
| 91 | + if is_matching_na(nulls_fixture, float("NaN")): |
| 92 | + index = Index(["a", float("NaN"), "b", float("NaN")]) |
| 93 | + indexer, missing = index.get_indexer_non_unique([nulls_fixture]) |
| 94 | + |
| 95 | + expected_indexer = np.array([1, 3], dtype=np.intp) |
| 96 | + tm.assert_numpy_array_equal(indexer, expected_indexer) |
| 97 | + tm.assert_numpy_array_equal(missing, expected_missing) |
| 98 | + |
| 99 | + |
69 | 100 | class TestSliceLocs:
|
70 | 101 | @pytest.mark.parametrize(
|
71 | 102 | "in_slice,expected",
|
|
0 commit comments