Skip to content

Commit

Permalink
TST: Added object array and NaT tests, moved to test_indexing (pandas…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhlim committed Aug 10, 2020
1 parent e6a00aa commit 2bea731
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
19 changes: 0 additions & 19 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2614,22 +2614,3 @@ def construct(dtype):
no_matches = np.array([-1] * 6, dtype=np.intp)
tm.assert_numpy_array_equal(result[0], no_matches)
tm.assert_numpy_array_equal(result[1], no_matches)


@pytest.mark.parametrize(
"idx, target, expected",
[
([np.nan, "var1", np.nan], [np.nan], np.array([0, 2], dtype=np.int64)),
(
[np.nan, "var1", np.nan],
[np.nan, "var1"],
np.array([0, 2, 1], dtype=np.int64),
),
],
)
def test_get_indexer_non_unique_multiple_nans(idx, target, expected):
# GH 35392
axis = pd.Index(idx)
actual = axis.get_indexer_for(target)

tm.assert_numpy_array_equal(actual, expected)
33 changes: 32 additions & 1 deletion pandas/tests/indexes/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
take
where
get_indexer
get_indexer_for
slice_locs
asof_locs
Expand All @@ -16,7 +17,9 @@
import numpy as np
import pytest

from pandas import Float64Index, Index, Int64Index, UInt64Index
from pandas._libs.tslibs import NaT

from pandas import DatetimeIndex, Float64Index, Index, Int64Index, UInt64Index
import pandas._testing as tm


Expand Down Expand Up @@ -96,3 +99,31 @@ def test_getitem_deprecated_float(idx):

expected = idx[1]
assert result == expected


@pytest.mark.parametrize(
"idx, target, expected",
[
([np.nan, "var1", np.nan], [np.nan], np.array([0, 2], dtype=np.int64)),
(
[np.nan, "var1", np.nan],
[np.nan, "var1"],
np.array([0, 2, 1], dtype=np.int64),
),
(
np.array([np.nan, "var1", np.nan], dtype=np.object),
[np.nan],
np.array([0, 2], dtype=np.int64),
),
(
DatetimeIndex(["2020-08-05", NaT, NaT]),
[NaT],
np.array([1, 2], dtype=np.int64),
),
],
)
def test_get_indexer_non_unique_multiple_nans(idx, target, expected):
# GH 35392
axis = Index(idx)
actual = axis.get_indexer_for(target)
tm.assert_numpy_array_equal(actual, expected)

0 comments on commit 2bea731

Please sign in to comment.