"""
Collection of tests asserting things that should be true for
any index subclass. Makes use of the `indices` fixture defined
in pandas/tests/indexes/conftest.py.
"""
import re

import numpy as np
import pytest

from pandas._libs.tslibs import iNaT

from pandas.core.dtypes.common import is_period_dtype, needs_i8_conversion

import pandas as pd
from pandas import (
    CategoricalIndex,
    DatetimeIndex,
    MultiIndex,
    PeriodIndex,
    RangeIndex,
    TimedeltaIndex,
)
import pandas._testing as tm


class TestCommon:
    def test_droplevel(self, index):
        # GH 21115
        if isinstance(index, MultiIndex):
            # Tested separately in test_multi.py
            return

        assert index.droplevel([]).equals(index)

        for level in index.name, [index.name]:
            if isinstance(index.name, tuple) and level is index.name:
                # GH 21121 : droplevel with tuple name
                continue
            with pytest.raises(ValueError):
                index.droplevel(level)

        for level in "wrong", ["wrong"]:
            with pytest.raises(
                KeyError,
                match=r"'Requested level \(wrong\) does not match index name \(None\)'",
            ):
                index.droplevel(level)

    def test_constructor_non_hashable_name(self, index):
        # GH 20527

        if isinstance(index, MultiIndex):
            pytest.skip("multiindex handled in test_multi.py")

        message = "Index.name must be a hashable type"
        renamed = [["1"]]

        # With .rename()
        with pytest.raises(TypeError, match=message):
            index.rename(name=renamed)

        # With .set_names()
        with pytest.raises(TypeError, match=message):
            index.set_names(names=renamed)

    def test_constructor_unwraps_index(self, index):
        if isinstance(index, pd.MultiIndex):
            raise pytest.skip("MultiIndex has no ._data")
        a = index
        b = type(a)(a)
        tm.assert_equal(a._data, b._data)

    @pytest.mark.parametrize("itm", [101, "no_int"])
    # FutureWarning from non-tuple sequence of nd indexing
    @pytest.mark.filterwarnings("ignore::FutureWarning")
    def test_getitem_error(self, index, itm):
        with pytest.raises(IndexError):
            index[itm]

    @pytest.mark.parametrize(
        "fname, sname, expected_name",
        [
            ("A", "A", "A"),
            ("A", "B", None),
            ("A", None, None),
            (None, "B", None),
            (None, None, None),
        ],
    )
    def test_corner_union(self, index, fname, sname, expected_name):
        # GH 9943 9862
        # Test unions with various name combinations
        # Do not test MultiIndex or repeats

        if isinstance(index, MultiIndex) or not index.is_unique:
            pytest.skip("Not for MultiIndex or repeated indices")

        # Test copy.union(copy)
        first = index.copy().set_names(fname)
        second = index.copy().set_names(sname)
        union = first.union(second)
        expected = index.copy().set_names(expected_name)
        tm.assert_index_equal(union, expected)

        # Test copy.union(empty)
        first = index.copy().set_names(fname)
        second = index.drop(index).set_names(sname)
        union = first.union(second)
        expected = index.copy().set_names(expected_name)
        tm.assert_index_equal(union, expected)

        # Test empty.union(copy)
        first = index.drop(index).set_names(fname)
        second = index.copy().set_names(sname)
        union = first.union(second)
        expected = index.copy().set_names(expected_name)
        tm.assert_index_equal(union, expected)

        # Test empty.union(empty)
        first = index.drop(index).set_names(fname)
        second = index.drop(index).set_names(sname)
        union = first.union(second)
        expected = index.drop(index).set_names(expected_name)
        tm.assert_index_equal(union, expected)

    @pytest.mark.parametrize(
        "fname, sname, expected_name",
        [
            ("A", "A", "A"),
            ("A", "B", None),
            ("A", None, None),
            (None, "B", None),
            (None, None, None),
        ],
    )
    def test_union_unequal(self, index, fname, sname, expected_name):
        if isinstance(index, MultiIndex) or not index.is_unique:
            pytest.skip("Not for MultiIndex or repeated indices")

        # test copy.union(subset) - need sort for unicode and string
        first = index.copy().set_names(fname)
        second = index[1:].set_names(sname)
        union = first.union(second).sort_values()
        expected = index.set_names(expected_name).sort_values()
        tm.assert_index_equal(union, expected)

    @pytest.mark.parametrize(
        "fname, sname, expected_name",
        [
            ("A", "A", "A"),
            ("A", "B", None),
            ("A", None, None),
            (None, "B", None),
            (None, None, None),
        ],
    )
    def test_corner_intersect(self, index, fname, sname, expected_name):
        # GH35847
        # Test intersections with various name combinations

        if isinstance(index, MultiIndex) or not index.is_unique:
            pytest.skip("Not for MultiIndex or repeated indices")

        # Test copy.intersection(copy)
        first = index.copy().set_names(fname)
        second = index.copy().set_names(sname)
        intersect = first.intersection(second)
        expected = index.copy().set_names(expected_name)
        tm.assert_index_equal(intersect, expected)

        # Test copy.intersection(empty)
        first = index.copy().set_names(fname)
        second = index.drop(index).set_names(sname)
        intersect = first.intersection(second)
        expected = index.drop(index).set_names(expected_name)
        tm.assert_index_equal(intersect, expected)

        # Test empty.intersection(copy)
        first = index.drop(index).set_names(fname)
        second = index.copy().set_names(sname)
        intersect = first.intersection(second)
        expected = index.drop(index).set_names(expected_name)
        tm.assert_index_equal(intersect, expected)

        # Test empty.intersection(empty)
        first = index.drop(index).set_names(fname)
        second = index.drop(index).set_names(sname)
        intersect = first.intersection(second)
        expected = index.drop(index).set_names(expected_name)
        tm.assert_index_equal(intersect, expected)

    @pytest.mark.parametrize(
        "fname, sname, expected_name",
        [
            ("A", "A", "A"),
            ("A", "B", None),
            ("A", None, None),
            (None, "B", None),
            (None, None, None),
        ],
    )
    def test_intersect_unequal(self, index, fname, sname, expected_name):
        if isinstance(index, MultiIndex) or not index.is_unique:
            pytest.skip("Not for MultiIndex or repeated indices")

        # test copy.intersection(subset) - need sort for unicode and string
        first = index.copy().set_names(fname)
        second = index[1:].set_names(sname)
        intersect = first.intersection(second).sort_values()
        expected = index[1:].set_names(expected_name).sort_values()
        tm.assert_index_equal(intersect, expected)

    def test_to_flat_index(self, index):
        # 22866
        if isinstance(index, MultiIndex):
            pytest.skip("Separate expectation for MultiIndex")

        result = index.to_flat_index()
        tm.assert_index_equal(result, index)

    def test_set_name_methods(self, index):
        new_name = "This is the new name for this index"

        # don't tests a MultiIndex here (as its tested separated)
        if isinstance(index, MultiIndex):
            pytest.skip("Skip check for MultiIndex")
        original_name = index.name
        new_ind = index.set_names([new_name])
        assert new_ind.name == new_name
        assert index.name == original_name
        res = index.rename(new_name, inplace=True)

        # should return None
        assert res is None
        assert index.name == new_name
        assert index.names == [new_name]
        # FIXME: dont leave commented-out
        # with pytest.raises(TypeError, match="list-like"):
        #    # should still fail even if it would be the right length
        #    ind.set_names("a")
        with pytest.raises(ValueError, match="Level must be None"):
            index.set_names("a", level=0)

        # rename in place just leaves tuples and other containers alone
        name = ("A", "B")
        index.rename(name, inplace=True)
        assert index.name == name
        assert index.names == [name]

    def test_copy_and_deepcopy(self, index):
        from copy import copy, deepcopy

        if isinstance(index, MultiIndex):
            pytest.skip("Skip check for MultiIndex")

        for func in (copy, deepcopy):
            idx_copy = func(index)
            assert idx_copy is not index
            assert idx_copy.equals(index)

        new_copy = index.copy(deep=True, name="banana")
        assert new_copy.name == "banana"

    def test_unique(self, index):
        # don't test a MultiIndex here (as its tested separated)
        # don't test a CategoricalIndex because categories change (GH 18291)
        if isinstance(index, (MultiIndex, CategoricalIndex)):
            pytest.skip("Skip check for MultiIndex/CategoricalIndex")

        # GH 17896
        expected = index.drop_duplicates()
        for level in 0, index.name, None:
            result = index.unique(level=level)
            tm.assert_index_equal(result, expected)

        msg = "Too many levels: Index has only 1 level, not 4"
        with pytest.raises(IndexError, match=msg):
            index.unique(level=3)

        msg = (
            fr"Requested level \(wrong\) does not match index name "
            fr"\({re.escape(index.name.__repr__())}\)"
        )
        with pytest.raises(KeyError, match=msg):
            index.unique(level="wrong")

    def test_get_unique_index(self, index):
        # MultiIndex tested separately
        if not len(index) or isinstance(index, MultiIndex):
            pytest.skip("Skip check for empty Index and MultiIndex")

        idx = index[[0] * 5]
        idx_unique = index[[0]]

        # We test against `idx_unique`, so first we make sure it's unique
        # and doesn't contain nans.
        assert idx_unique.is_unique is True
        try:
            assert idx_unique.hasnans is False
        except NotImplementedError:
            pass

        for dropna in [False, True]:
            result = idx._get_unique_index(dropna=dropna)
            tm.assert_index_equal(result, idx_unique)

        # nans:
        if not index._can_hold_na:
            pytest.skip("Skip na-check if index cannot hold na")

        if is_period_dtype(index.dtype):
            vals = index[[0] * 5]._data
            vals[0] = pd.NaT
        elif needs_i8_conversion(index.dtype):
            vals = index.asi8[[0] * 5]
            vals[0] = iNaT
        else:
            vals = index.values[[0] * 5]
            vals[0] = np.nan

        vals_unique = vals[:2]
        if index.dtype.kind in ["m", "M"]:
            # i.e. needs_i8_conversion but not period_dtype, as above
            vals = type(index._data)._simple_new(vals, dtype=index.dtype)
            vals_unique = type(index._data)._simple_new(vals_unique, dtype=index.dtype)
        idx_nan = index._shallow_copy(vals)
        idx_unique_nan = index._shallow_copy(vals_unique)
        assert idx_unique_nan.is_unique is True

        assert idx_nan.dtype == index.dtype
        assert idx_unique_nan.dtype == index.dtype

        for dropna, expected in zip([False, True], [idx_unique_nan, idx_unique]):
            for i in [idx_nan, idx_unique_nan]:
                result = i._get_unique_index(dropna=dropna)
                tm.assert_index_equal(result, expected)

    def test_mutability(self, index):
        if not len(index):
            pytest.skip("Skip check for empty Index")
        msg = "Index does not support mutable operations"
        with pytest.raises(TypeError, match=msg):
            index[0] = index[0]

    def test_view(self, index):
        assert index.view().name == index.name

    def test_searchsorted_monotonic(self, index):
        # GH17271
        # not implemented for tuple searches in MultiIndex
        # or Intervals searches in IntervalIndex
        if isinstance(index, (MultiIndex, pd.IntervalIndex)):
            pytest.skip("Skip check for MultiIndex/IntervalIndex")

        # nothing to test if the index is empty
        if index.empty:
            pytest.skip("Skip check for empty Index")
        value = index[0]

        # determine the expected results (handle dupes for 'right')
        expected_left, expected_right = 0, (index == value).argmin()
        if expected_right == 0:
            # all values are the same, expected_right should be length
            expected_right = len(index)

        # test _searchsorted_monotonic in all cases
        # test searchsorted only for increasing
        if index.is_monotonic_increasing:
            ssm_left = index._searchsorted_monotonic(value, side="left")
            assert expected_left == ssm_left

            ssm_right = index._searchsorted_monotonic(value, side="right")
            assert expected_right == ssm_right

            ss_left = index.searchsorted(value, side="left")
            assert expected_left == ss_left

            ss_right = index.searchsorted(value, side="right")
            assert expected_right == ss_right

        elif index.is_monotonic_decreasing:
            ssm_left = index._searchsorted_monotonic(value, side="left")
            assert expected_left == ssm_left

            ssm_right = index._searchsorted_monotonic(value, side="right")
            assert expected_right == ssm_right
        else:
            # non-monotonic should raise.
            with pytest.raises(ValueError):
                index._searchsorted_monotonic(value, side="left")

    def test_pickle(self, index):
        original_name, index.name = index.name, "foo"
        unpickled = tm.round_trip_pickle(index)
        assert index.equals(unpickled)
        index.name = original_name

    def test_drop_duplicates(self, index, keep):
        if isinstance(index, MultiIndex):
            pytest.skip("MultiIndex is tested separately")
        if isinstance(index, RangeIndex):
            pytest.skip(
                "RangeIndex is tested in test_drop_duplicates_no_duplicates "
                "as it cannot hold duplicates"
            )
        if len(index) == 0:
            pytest.skip(
                "empty index is tested in test_drop_duplicates_no_duplicates "
                "as it cannot hold duplicates"
            )

        # make unique index
        holder = type(index)
        unique_values = list(set(index))
        unique_idx = holder(unique_values)

        # make duplicated index
        n = len(unique_idx)
        duplicated_selection = np.random.choice(n, int(n * 1.5))
        idx = holder(unique_idx.values[duplicated_selection])

        # Series.duplicated is tested separately
        expected_duplicated = (
            pd.Series(duplicated_selection).duplicated(keep=keep).values
        )
        tm.assert_numpy_array_equal(idx.duplicated(keep=keep), expected_duplicated)

        # Series.drop_duplicates is tested separately
        expected_dropped = holder(pd.Series(idx).drop_duplicates(keep=keep))
        tm.assert_index_equal(idx.drop_duplicates(keep=keep), expected_dropped)

    def test_drop_duplicates_no_duplicates(self, index):
        if isinstance(index, MultiIndex):
            pytest.skip("MultiIndex is tested separately")

        # make unique index
        if isinstance(index, RangeIndex):
            # RangeIndex cannot have duplicates
            unique_idx = index
        else:
            holder = type(index)
            unique_values = list(set(index))
            unique_idx = holder(unique_values)

        # check on unique index
        expected_duplicated = np.array([False] * len(unique_idx), dtype="bool")
        tm.assert_numpy_array_equal(unique_idx.duplicated(), expected_duplicated)
        result_dropped = unique_idx.drop_duplicates()
        tm.assert_index_equal(result_dropped, unique_idx)
        # validate shallow copy
        assert result_dropped is not unique_idx

    def test_drop_duplicates_inplace(self, index):
        msg = r"drop_duplicates\(\) got an unexpected keyword argument"
        with pytest.raises(TypeError, match=msg):
            index.drop_duplicates(inplace=True)

    def test_has_duplicates(self, index):
        holder = type(index)
        if not len(index) or isinstance(index, (MultiIndex, RangeIndex)):
            # MultiIndex tested separately in:
            #   tests/indexes/multi/test_unique_and_duplicates.
            # RangeIndex is unique by definition.
            pytest.skip("Skip check for empty Index, MultiIndex, and RangeIndex")

        idx = holder([index[0]] * 5)
        assert idx.is_unique is False
        assert idx.has_duplicates is True

    @pytest.mark.parametrize(
        "dtype",
        ["int64", "uint64", "float64", "category", "datetime64[ns]", "timedelta64[ns]"],
    )
    def test_astype_preserves_name(self, index, dtype):
        # https://github.com/pandas-dev/pandas/issues/32013
        if isinstance(index, MultiIndex):
            index.names = ["idx" + str(i) for i in range(index.nlevels)]
        else:
            index.name = "idx"

        try:
            # Some of these conversions cannot succeed so we use a try / except
            result = index.astype(dtype)
        except (ValueError, TypeError, NotImplementedError, SystemError):
            return

        if isinstance(index, MultiIndex):
            assert result.names == index.names
        else:
            assert result.name == index.name

    def test_ravel_deprecation(self, index):
        # GH#19956 ravel returning ndarray is deprecated
        with tm.assert_produces_warning(FutureWarning):
            index.ravel()


@pytest.mark.parametrize("na_position", [None, "middle"])
def test_sort_values_invalid_na_position(index_with_missing, na_position):
    if isinstance(index_with_missing, (DatetimeIndex, PeriodIndex, TimedeltaIndex)):
        # datetime-like indices will get na_position kwarg as part of
        # synchronizing duplicate-sorting behavior, because we currently expect
        # them, other indices, and Series to sort differently (xref 35922)
        pytest.xfail("sort_values does not support na_position kwarg")
    elif isinstance(index_with_missing, (CategoricalIndex, MultiIndex)):
        pytest.xfail("missing value sorting order not defined for index type")

    if na_position not in ["first", "last"]:
        with pytest.raises(ValueError, match=f"invalid na_position: {na_position}"):
            index_with_missing.sort_values(na_position=na_position)


@pytest.mark.parametrize("na_position", ["first", "last"])
def test_sort_values_with_missing(index_with_missing, na_position):
    # GH 35584. Test that sort_values works with missing values,
    # sort non-missing and place missing according to na_position

    if isinstance(index_with_missing, (DatetimeIndex, PeriodIndex, TimedeltaIndex)):
        # datetime-like indices will get na_position kwarg as part of
        # synchronizing duplicate-sorting behavior, because we currently expect
        # them, other indices, and Series to sort differently (xref 35922)
        pytest.xfail("sort_values does not support na_position kwarg")
    elif isinstance(index_with_missing, (CategoricalIndex, MultiIndex)):
        pytest.xfail("missing value sorting order not defined for index type")

    missing_count = np.sum(index_with_missing.isna())
    not_na_vals = index_with_missing[index_with_missing.notna()].values
    sorted_values = np.sort(not_na_vals)
    if na_position == "first":
        sorted_values = np.concatenate([[None] * missing_count, sorted_values])
    else:
        sorted_values = np.concatenate([sorted_values, [None] * missing_count])
    expected = type(index_with_missing)(sorted_values)

    result = index_with_missing.sort_values(na_position=na_position)
    tm.assert_index_equal(result, expected)

[((18137, 18193), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""na_position"""', "[None, 'middle']"], {}), "('na_position', [None, 'middle'])\n", (18160, 18193), False, 'import pytest\n'), ((19004, 19061), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""na_position"""', "['first', 'last']"], {}), "('na_position', ['first', 'last'])\n", (19027, 19061), False, 'import pytest\n'), ((2026, 2073), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""itm"""', "[101, 'no_int']"], {}), "('itm', [101, 'no_int'])\n", (2049, 2073), False, 'import pytest\n'), ((2138, 2189), 'pytest.mark.filterwarnings', 'pytest.mark.filterwarnings', (['"""ignore::FutureWarning"""'], {}), "('ignore::FutureWarning')\n", (2164, 2189), False, 'import pytest\n'), ((2305, 2459), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""fname, sname, expected_name"""', "[('A', 'A', 'A'), ('A', 'B', None), ('A', None, None), (None, 'B', None), (\n    None, None, None)]"], {}), "('fname, sname, expected_name', [('A', 'A', 'A'), (\n    'A', 'B', None), ('A', None, None), (None, 'B', None), (None, None, None)])\n", (2328, 2459), False, 'import pytest\n'), ((3969, 4123), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""fname, sname, expected_name"""', "[('A', 'A', 'A'), ('A', 'B', None), ('A', None, None), (None, 'B', None), (\n    None, None, None)]"], {}), "('fname, sname, expected_name', [('A', 'A', 'A'), (\n    'A', 'B', None), ('A', None, None), (None, 'B', None), (None, None, None)])\n", (3992, 4123), False, 'import pytest\n'), ((4741, 4895), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""fname, sname, expected_name"""', "[('A', 'A', 'A'), ('A', 'B', None), ('A', None, None), (None, 'B', None), (\n    None, None, None)]"], {}), "('fname, sname, expected_name', [('A', 'A', 'A'), (\n    'A', 'B', None), ('A', None, None), (None, 'B', None), (None, None, None)])\n", (4764, 4895), False, 'import pytest\n'), ((6465, 6619), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""fname, sname, expected_name"""', "[('A', 'A', 'A'), ('A', 'B', None), ('A', None, None), (None, 'B', None), (\n    None, None, None)]"], {}), "('fname, sname, expected_name', [('A', 'A', 'A'), (\n    'A', 'B', None), ('A', None, None), (None, 'B', None), (None, None, None)])\n", (6488, 6619), False, 'import pytest\n'), ((17159, 17276), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""dtype"""', "['int64', 'uint64', 'float64', 'category', 'datetime64[ns]', 'timedelta64[ns]']"], {}), "('dtype', ['int64', 'uint64', 'float64', 'category',\n    'datetime64[ns]', 'timedelta64[ns]'])\n", (17182, 17276), False, 'import pytest\n'), ((19942, 19962), 'numpy.sort', 'np.sort', (['not_na_vals'], {}), '(not_na_vals)\n', (19949, 19962), True, 'import numpy as np\n'), ((20293, 20332), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['result', 'expected'], {}), '(result, expected)\n', (20314, 20332), True, 'import pandas._testing as tm\n'), ((1986, 2019), 'pandas._testing.assert_equal', 'tm.assert_equal', (['a._data', 'b._data'], {}), '(a._data, b._data)\n', (2001, 2019), True, 'import pandas._testing as tm\n'), ((3097, 3135), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['union', 'expected'], {}), '(union, expected)\n', (3118, 3135), True, 'import pandas._testing as tm\n'), ((3369, 3407), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['union', 'expected'], {}), '(union, expected)\n', (3390, 3407), True, 'import pandas._testing as tm\n'), ((3641, 3679), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['union', 'expected'], {}), '(union, expected)\n', (3662, 3679), True, 'import pandas._testing as tm\n'), ((3924, 3962), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['union', 'expected'], {}), '(union, expected)\n', (3945, 3962), True, 'import pandas._testing as tm\n'), ((4696, 4734), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['union', 'expected'], {}), '(union, expected)\n', (4717, 4734), True, 'import pandas._testing as tm\n'), ((5513, 5555), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['intersect', 'expected'], {}), '(intersect, expected)\n', (5534, 5555), True, 'import pandas._testing as tm\n'), ((5812, 5854), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['intersect', 'expected'], {}), '(intersect, expected)\n', (5833, 5854), True, 'import pandas._testing as tm\n'), ((6111, 6153), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['intersect', 'expected'], {}), '(intersect, expected)\n', (6132, 6153), True, 'import pandas._testing as tm\n'), ((6416, 6458), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['intersect', 'expected'], {}), '(intersect, expected)\n', (6437, 6458), True, 'import pandas._testing as tm\n'), ((7218, 7260), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['intersect', 'expected'], {}), '(intersect, expected)\n', (7239, 7260), True, 'import pandas._testing as tm\n'), ((7472, 7508), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['result', 'index'], {}), '(result, index)\n', (7493, 7508), True, 'import pandas._testing as tm\n'), ((10810, 10838), 'pandas.core.dtypes.common.is_period_dtype', 'is_period_dtype', (['index.dtype'], {}), '(index.dtype)\n', (10825, 10838), False, 'from pandas.core.dtypes.common import is_period_dtype, needs_i8_conversion\n'), ((14146, 14173), 'pandas._testing.round_trip_pickle', 'tm.round_trip_pickle', (['index'], {}), '(index)\n', (14166, 14173), True, 'import pandas._testing as tm\n'), ((16294, 16343), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['result_dropped', 'unique_idx'], {}), '(result_dropped, unique_idx)\n', (16315, 16343), True, 'import pandas._testing as tm\n'), ((18587, 18649), 'pytest.xfail', 'pytest.xfail', (['"""sort_values does not support na_position kwarg"""'], {}), "('sort_values does not support na_position kwarg')\n", (18599, 18649), False, 'import pytest\n'), ((19580, 19642), 'pytest.xfail', 'pytest.xfail', (['"""sort_values does not support na_position kwarg"""'], {}), "('sort_values does not support na_position kwarg')\n", (19592, 19642), False, 'import pytest\n'), ((20018, 20073), 'numpy.concatenate', 'np.concatenate', (['[[None] * missing_count, sorted_values]'], {}), '([[None] * missing_count, sorted_values])\n', (20032, 20073), True, 'import numpy as np\n'), ((20108, 20163), 'numpy.concatenate', 'np.concatenate', (['[sorted_values, [None] * missing_count]'], {}), '([sorted_values, [None] * missing_count])\n', (20122, 20163), True, 'import numpy as np\n'), ((1402, 1452), 'pytest.skip', 'pytest.skip', (['"""multiindex handled in test_multi.py"""'], {}), "('multiindex handled in test_multi.py')\n", (1413, 1452), False, 'import pytest\n'), ((1574, 1613), 'pytest.raises', 'pytest.raises', (['TypeError'], {'match': 'message'}), '(TypeError, match=message)\n', (1587, 1613), False, 'import pytest\n'), ((1696, 1735), 'pytest.raises', 'pytest.raises', (['TypeError'], {'match': 'message'}), '(TypeError, match=message)\n', (1709, 1735), False, 'import pytest\n'), ((1897, 1936), 'pytest.skip', 'pytest.skip', (['"""MultiIndex has no ._data"""'], {}), "('MultiIndex has no ._data')\n", (1908, 1936), False, 'import pytest\n'), ((2249, 2274), 'pytest.raises', 'pytest.raises', (['IndexError'], {}), '(IndexError)\n', (2262, 2274), False, 'import pytest\n'), ((2816, 2869), 'pytest.skip', 'pytest.skip', (['"""Not for MultiIndex or repeated indices"""'], {}), "('Not for MultiIndex or repeated indices')\n", (2827, 2869), False, 'import pytest\n'), ((4360, 4413), 'pytest.skip', 'pytest.skip', (['"""Not for MultiIndex or repeated indices"""'], {}), "('Not for MultiIndex or repeated indices')\n", (4371, 4413), False, 'import pytest\n'), ((5214, 5267), 'pytest.skip', 'pytest.skip', (['"""Not for MultiIndex or repeated indices"""'], {}), "('Not for MultiIndex or repeated indices')\n", (5225, 5267), False, 'import pytest\n'), ((6860, 6913), 'pytest.skip', 'pytest.skip', (['"""Not for MultiIndex or repeated indices"""'], {}), "('Not for MultiIndex or repeated indices')\n", (6871, 6913), False, 'import pytest\n'), ((7373, 7423), 'pytest.skip', 'pytest.skip', (['"""Separate expectation for MultiIndex"""'], {}), "('Separate expectation for MultiIndex')\n", (7384, 7423), False, 'import pytest\n'), ((7732, 7772), 'pytest.skip', 'pytest.skip', (['"""Skip check for MultiIndex"""'], {}), "('Skip check for MultiIndex')\n", (7743, 7772), False, 'import pytest\n'), ((8341, 8394), 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '"""Level must be None"""'}), "(ValueError, match='Level must be None')\n", (8354, 8394), False, 'import pytest\n'), ((8790, 8830), 'pytest.skip', 'pytest.skip', (['"""Skip check for MultiIndex"""'], {}), "('Skip check for MultiIndex')\n", (8801, 8830), False, 'import pytest\n'), ((9337, 9394), 'pytest.skip', 'pytest.skip', (['"""Skip check for MultiIndex/CategoricalIndex"""'], {}), "('Skip check for MultiIndex/CategoricalIndex')\n", (9348, 9394), False, 'import pytest\n'), ((9559, 9598), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['result', 'expected'], {}), '(result, expected)\n', (9580, 9598), True, 'import pandas._testing as tm\n'), ((9676, 9712), 'pytest.raises', 'pytest.raises', (['IndexError'], {'match': 'msg'}), '(IndexError, match=msg)\n', (9689, 9712), False, 'import pytest\n'), ((9912, 9946), 'pytest.raises', 'pytest.raises', (['KeyError'], {'match': 'msg'}), '(KeyError, match=msg)\n', (9925, 9946), False, 'import pytest\n'), ((10144, 10200), 'pytest.skip', 'pytest.skip', (['"""Skip check for empty Index and MultiIndex"""'], {}), "('Skip check for empty Index and MultiIndex')\n", (10155, 10200), False, 'import pytest\n'), ((10639, 10680), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['result', 'idx_unique'], {}), '(result, idx_unique)\n', (10660, 10680), True, 'import pandas._testing as tm\n'), ((10745, 10797), 'pytest.skip', 'pytest.skip', (['"""Skip na-check if index cannot hold na"""'], {}), "('Skip na-check if index cannot hold na')\n", (10756, 10797), False, 'import pytest\n'), ((10922, 10954), 'pandas.core.dtypes.common.needs_i8_conversion', 'needs_i8_conversion', (['index.dtype'], {}), '(index.dtype)\n', (10941, 10954), False, 'from pandas.core.dtypes.common import is_period_dtype, needs_i8_conversion\n'), ((11984, 12025), 'pytest.skip', 'pytest.skip', (['"""Skip check for empty Index"""'], {}), "('Skip check for empty Index')\n", (11995, 12025), False, 'import pytest\n'), ((12097, 12132), 'pytest.raises', 'pytest.raises', (['TypeError'], {'match': 'msg'}), '(TypeError, match=msg)\n', (12110, 12132), False, 'import pytest\n'), ((12497, 12551), 'pytest.skip', 'pytest.skip', (['"""Skip check for MultiIndex/IntervalIndex"""'], {}), "('Skip check for MultiIndex/IntervalIndex')\n", (12508, 12551), False, 'import pytest\n'), ((12637, 12678), 'pytest.skip', 'pytest.skip', (['"""Skip check for empty Index"""'], {}), "('Skip check for empty Index')\n", (12648, 12678), False, 'import pytest\n'), ((14352, 14398), 'pytest.skip', 'pytest.skip', (['"""MultiIndex is tested separately"""'], {}), "('MultiIndex is tested separately')\n", (14363, 14398), False, 'import pytest\n'), ((14453, 14565), 'pytest.skip', 'pytest.skip', (['"""RangeIndex is tested in test_drop_duplicates_no_duplicates as it cannot hold duplicates"""'], {}), "(\n    'RangeIndex is tested in test_drop_duplicates_no_duplicates as it cannot hold duplicates'\n    )\n", (14464, 14565), False, 'import pytest\n'), ((14645, 14758), 'pytest.skip', 'pytest.skip', (['"""empty index is tested in test_drop_duplicates_no_duplicates as it cannot hold duplicates"""'], {}), "(\n    'empty index is tested in test_drop_duplicates_no_duplicates as it cannot hold duplicates'\n    )\n", (14656, 14758), False, 'import pytest\n'), ((15701, 15747), 'pytest.skip', 'pytest.skip', (['"""MultiIndex is tested separately"""'], {}), "('MultiIndex is tested separately')\n", (15712, 15747), False, 'import pytest\n'), ((16561, 16596), 'pytest.raises', 'pytest.raises', (['TypeError'], {'match': 'msg'}), '(TypeError, match=msg)\n', (16574, 16596), False, 'import pytest\n'), ((16965, 17034), 'pytest.skip', 'pytest.skip', (['"""Skip check for empty Index, MultiIndex, and RangeIndex"""'], {}), "('Skip check for empty Index, MultiIndex, and RangeIndex')\n", (16976, 17034), False, 'import pytest\n'), ((18065, 18106), 'pandas._testing.assert_produces_warning', 'tm.assert_produces_warning', (['FutureWarning'], {}), '(FutureWarning)\n', (18091, 18106), True, 'import pandas._testing as tm\n'), ((18731, 18801), 'pytest.xfail', 'pytest.xfail', (['"""missing value sorting order not defined for index type"""'], {}), "('missing value sorting order not defined for index type')\n", (18743, 18801), False, 'import pytest\n'), ((18861, 18931), 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': 'f"""invalid na_position: {na_position}"""'}), "(ValueError, match=f'invalid na_position: {na_position}')\n", (18874, 18931), False, 'import pytest\n'), ((19724, 19794), 'pytest.xfail', 'pytest.xfail', (['"""missing value sorting order not defined for index type"""'], {}), "('missing value sorting order not defined for index type')\n", (19736, 19794), False, 'import pytest\n'), ((961, 986), 'pytest.raises', 'pytest.raises', (['ValueError'], {}), '(ValueError)\n', (974, 986), False, 'import pytest\n'), ((1086, 1190), 'pytest.raises', 'pytest.raises', (['KeyError'], {'match': '"""\'Requested level \\\\(wrong\\\\) does not match index name \\\\(None\\\\)\'"""'}), '(KeyError, match=\n    "\'Requested level \\\\(wrong\\\\) does not match index name \\\\(None\\\\)\'")\n', (1099, 1190), False, 'import pytest\n'), ((11866, 11905), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', (['result', 'expected'], {}), '(result, expected)\n', (11887, 11905), True, 'import pandas._testing as tm\n'), ((13944, 13969), 'pytest.raises', 'pytest.raises', (['ValueError'], {}), '(ValueError)\n', (13957, 13969), False, 'import pytest\n'), ((15222, 15253), 'pandas.Series', 'pd.Series', (['duplicated_selection'], {}), '(duplicated_selection)\n', (15231, 15253), True, 'import pandas as pd\n'), ((15466, 15480), 'pandas.Series', 'pd.Series', (['idx'], {}), '(idx)\n', (15475, 15480), True, 'import pandas as pd\n')]