"""
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)

[((499, 1, 499, 57), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(499, 25, 499, 38): '"""na_position"""', (499, 40, 499, 56): "[None, 'middle']"}, {}), "('na_position', [None, 'middle'])", False, 'import pytest\n'), ((514, 1, 514, 58), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(514, 25, 514, 38): '"""na_position"""', (514, 40, 514, 57): "['first', 'last']"}, {}), "('na_position', ['first', 'last'])", False, 'import pytest\n'), ((74, 5, 74, 52), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(74, 29, 74, 34): '"""itm"""', (74, 36, 74, 51): "[101, 'no_int']"}, {}), "('itm', [101, 'no_int'])", False, 'import pytest\n'), ((76, 5, 76, 56), 'pytest.mark.filterwarnings', 'pytest.mark.filterwarnings', ({(76, 32, 76, 55): '"""ignore::FutureWarning"""'}, {}), "('ignore::FutureWarning')", False, 'import pytest\n'), ((81, 5, 90, 5), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(82, 8, 82, 37): '"""fname, sname, expected_name"""', (83, 8, 89, 9): "[('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)])", False, 'import pytest\n'), ((127, 5, 136, 5), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(128, 8, 128, 37): '"""fname, sname, expected_name"""', (129, 8, 135, 9): "[('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)])", False, 'import pytest\n'), ((148, 5, 157, 5), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(149, 8, 149, 37): '"""fname, sname, expected_name"""', (150, 8, 156, 9): "[('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)])", False, 'import pytest\n'), ((193, 5, 202, 5), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(194, 8, 194, 37): '"""fname, sname, expected_name"""', (195, 8, 201, 9): "[('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)])", False, 'import pytest\n'), ((471, 5, 474, 5), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(472, 8, 472, 15): '"""dtype"""', (473, 8, 473, 87): "['int64', 'uint64', 'float64', 'category', 'datetime64[ns]', 'timedelta64[ns]']"}, {}), "('dtype', ['int64', 'uint64', 'float64', 'category',\n    'datetime64[ns]', 'timedelta64[ns]'])", False, 'import pytest\n'), ((529, 20, 529, 40), 'numpy.sort', 'np.sort', ({(529, 28, 529, 39): 'not_na_vals'}, {}), '(not_na_vals)', True, 'import numpy as np\n'), ((537, 4, 537, 43), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(537, 26, 537, 32): 'result', (537, 34, 537, 42): 'expected'}, {}), '(result, expected)', True, 'import pandas._testing as tm\n'), ((72, 8, 72, 41), 'pandas._testing.assert_equal', 'tm.assert_equal', ({(72, 24, 72, 31): 'a._data', (72, 33, 72, 40): 'b._data'}, {}), '(a._data, b._data)', True, 'import pandas._testing as tm\n'), ((104, 8, 104, 46), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(104, 30, 104, 35): 'union', (104, 37, 104, 45): 'expected'}, {}), '(union, expected)', True, 'import pandas._testing as tm\n'), ((111, 8, 111, 46), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(111, 30, 111, 35): 'union', (111, 37, 111, 45): 'expected'}, {}), '(union, expected)', True, 'import pandas._testing as tm\n'), ((118, 8, 118, 46), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(118, 30, 118, 35): 'union', (118, 37, 118, 45): 'expected'}, {}), '(union, expected)', True, 'import pandas._testing as tm\n'), ((125, 8, 125, 46), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(125, 30, 125, 35): 'union', (125, 37, 125, 45): 'expected'}, {}), '(union, expected)', True, 'import pandas._testing as tm\n'), ((146, 8, 146, 46), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(146, 30, 146, 35): 'union', (146, 37, 146, 45): 'expected'}, {}), '(union, expected)', True, 'import pandas._testing as tm\n'), ((170, 8, 170, 50), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(170, 30, 170, 39): 'intersect', (170, 41, 170, 49): 'expected'}, {}), '(intersect, expected)', True, 'import pandas._testing as tm\n'), ((177, 8, 177, 50), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(177, 30, 177, 39): 'intersect', (177, 41, 177, 49): 'expected'}, {}), '(intersect, expected)', True, 'import pandas._testing as tm\n'), ((184, 8, 184, 50), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(184, 30, 184, 39): 'intersect', (184, 41, 184, 49): 'expected'}, {}), '(intersect, expected)', True, 'import pandas._testing as tm\n'), ((191, 8, 191, 50), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(191, 30, 191, 39): 'intersect', (191, 41, 191, 49): 'expected'}, {}), '(intersect, expected)', True, 'import pandas._testing as tm\n'), ((212, 8, 212, 50), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(212, 30, 212, 39): 'intersect', (212, 41, 212, 49): 'expected'}, {}), '(intersect, expected)', True, 'import pandas._testing as tm\n'), ((220, 8, 220, 44), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(220, 30, 220, 36): 'result', (220, 38, 220, 43): 'index'}, {}), '(result, index)', True, 'import pandas._testing as tm\n'), ((312, 11, 312, 39), 'pandas.core.dtypes.common.is_period_dtype', 'is_period_dtype', ({(312, 27, 312, 38): 'index.dtype'}, {}), '(index.dtype)', False, 'from pandas.core.dtypes.common import is_period_dtype, needs_i8_conversion\n'), ((395, 20, 395, 47), 'pandas._testing.round_trip_pickle', 'tm.round_trip_pickle', ({(395, 41, 395, 46): 'index'}, {}), '(index)', True, 'import pandas._testing as tm\n'), ((450, 8, 450, 57), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(450, 30, 450, 44): 'result_dropped', (450, 46, 450, 56): 'unique_idx'}, {}), '(result_dropped, unique_idx)', True, 'import pandas._testing as tm\n'), ((505, 8, 505, 70), 'pytest.xfail', 'pytest.xfail', ({(505, 21, 505, 69): '"""sort_values does not support na_position kwarg"""'}, {}), "('sort_values does not support na_position kwarg')", False, 'import pytest\n'), ((523, 8, 523, 70), 'pytest.xfail', 'pytest.xfail', ({(523, 21, 523, 69): '"""sort_values does not support na_position kwarg"""'}, {}), "('sort_values does not support na_position kwarg')", False, 'import pytest\n'), ((531, 24, 531, 79), 'numpy.concatenate', 'np.concatenate', ({(531, 39, 531, 78): '[[None] * missing_count, sorted_values]'}, {}), '([[None] * missing_count, sorted_values])', True, 'import numpy as np\n'), ((533, 24, 533, 79), 'numpy.concatenate', 'np.concatenate', ({(533, 39, 533, 78): '[sorted_values, [None] * missing_count]'}, {}), '([sorted_values, [None] * missing_count])', True, 'import numpy as np\n'), ((54, 12, 54, 62), 'pytest.skip', 'pytest.skip', ({(54, 24, 54, 61): '"""multiindex handled in test_multi.py"""'}, {}), "('multiindex handled in test_multi.py')", False, 'import pytest\n'), ((60, 13, 60, 52), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((64, 13, 64, 52), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((69, 18, 69, 57), 'pytest.skip', 'pytest.skip', ({(69, 30, 69, 56): '"""MultiIndex has no ._data"""'}, {}), "('MultiIndex has no ._data')", False, 'import pytest\n'), ((78, 13, 78, 38), 'pytest.raises', 'pytest.raises', ({(78, 27, 78, 37): 'IndexError'}, {}), '(IndexError)', False, 'import pytest\n'), ((97, 12, 97, 65), 'pytest.skip', 'pytest.skip', ({(97, 24, 97, 64): '"""Not for MultiIndex or repeated indices"""'}, {}), "('Not for MultiIndex or repeated indices')", False, 'import pytest\n'), ((139, 12, 139, 65), 'pytest.skip', 'pytest.skip', ({(139, 24, 139, 64): '"""Not for MultiIndex or repeated indices"""'}, {}), "('Not for MultiIndex or repeated indices')", False, 'import pytest\n'), ((163, 12, 163, 65), 'pytest.skip', 'pytest.skip', ({(163, 24, 163, 64): '"""Not for MultiIndex or repeated indices"""'}, {}), "('Not for MultiIndex or repeated indices')", False, 'import pytest\n'), ((205, 12, 205, 65), 'pytest.skip', 'pytest.skip', ({(205, 24, 205, 64): '"""Not for MultiIndex or repeated indices"""'}, {}), "('Not for MultiIndex or repeated indices')", False, 'import pytest\n'), ((217, 12, 217, 62), 'pytest.skip', 'pytest.skip', ({(217, 24, 217, 61): '"""Separate expectation for MultiIndex"""'}, {}), "('Separate expectation for MultiIndex')", False, 'import pytest\n'), ((227, 12, 227, 52), 'pytest.skip', 'pytest.skip', ({(227, 24, 227, 51): '"""Skip check for MultiIndex"""'}, {}), "('Skip check for MultiIndex')", False, 'import pytest\n'), ((242, 13, 242, 66), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((255, 12, 255, 52), 'pytest.skip', 'pytest.skip', ({(255, 24, 255, 51): '"""Skip check for MultiIndex"""'}, {}), "('Skip check for MultiIndex')", False, 'import pytest\n'), ((269, 12, 269, 69), 'pytest.skip', 'pytest.skip', ({(269, 24, 269, 68): '"""Skip check for MultiIndex/CategoricalIndex"""'}, {}), "('Skip check for MultiIndex/CategoricalIndex')", False, 'import pytest\n'), ((275, 12, 275, 51), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(275, 34, 275, 40): 'result', (275, 42, 275, 50): 'expected'}, {}), '(result, expected)', True, 'import pandas._testing as tm\n'), ((278, 13, 278, 49), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((285, 13, 285, 47), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((291, 12, 291, 68), 'pytest.skip', 'pytest.skip', ({(291, 24, 291, 67): '"""Skip check for empty Index and MultiIndex"""'}, {}), "('Skip check for empty Index and MultiIndex')", False, 'import pytest\n'), ((306, 12, 306, 53), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(306, 34, 306, 40): 'result', (306, 42, 306, 52): 'idx_unique'}, {}), '(result, idx_unique)', True, 'import pandas._testing as tm\n'), ((310, 12, 310, 64), 'pytest.skip', 'pytest.skip', ({(310, 24, 310, 63): '"""Skip na-check if index cannot hold na"""'}, {}), "('Skip na-check if index cannot hold na')", False, 'import pytest\n'), ((315, 13, 315, 45), 'pandas.core.dtypes.common.needs_i8_conversion', 'needs_i8_conversion', ({(315, 33, 315, 44): 'index.dtype'}, {}), '(index.dtype)', False, 'from pandas.core.dtypes.common import is_period_dtype, needs_i8_conversion\n'), ((341, 12, 341, 53), 'pytest.skip', 'pytest.skip', ({(341, 24, 341, 52): '"""Skip check for empty Index"""'}, {}), "('Skip check for empty Index')", False, 'import pytest\n'), ((343, 13, 343, 48), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((354, 12, 354, 66), 'pytest.skip', 'pytest.skip', ({(354, 24, 354, 65): '"""Skip check for MultiIndex/IntervalIndex"""'}, {}), "('Skip check for MultiIndex/IntervalIndex')", False, 'import pytest\n'), ((358, 12, 358, 53), 'pytest.skip', 'pytest.skip', ({(358, 24, 358, 52): '"""Skip check for empty Index"""'}, {}), "('Skip check for empty Index')", False, 'import pytest\n'), ((401, 12, 401, 58), 'pytest.skip', 'pytest.skip', ({(401, 24, 401, 57): '"""MultiIndex is tested separately"""'}, {}), "('MultiIndex is tested separately')", False, 'import pytest\n'), ((403, 12, 406, 13), 'pytest.skip', 'pytest.skip', ({(404, 16, 405, 46): '"""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    )", False, 'import pytest\n'), ((408, 12, 411, 13), 'pytest.skip', 'pytest.skip', ({(409, 16, 410, 46): '"""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    )", False, 'import pytest\n'), ((435, 12, 435, 58), 'pytest.skip', 'pytest.skip', ({(435, 24, 435, 57): '"""MultiIndex is tested separately"""'}, {}), "('MultiIndex is tested separately')", False, 'import pytest\n'), ((456, 13, 456, 48), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((465, 12, 465, 81), 'pytest.skip', 'pytest.skip', ({(465, 24, 465, 80): '"""Skip check for empty Index, MultiIndex, and RangeIndex"""'}, {}), "('Skip check for empty Index, MultiIndex, and RangeIndex')", False, 'import pytest\n'), ((495, 13, 495, 54), 'pandas._testing.assert_produces_warning', 'tm.assert_produces_warning', ({(495, 40, 495, 53): 'FutureWarning'}, {}), '(FutureWarning)', True, 'import pandas._testing as tm\n'), ((507, 8, 507, 78), 'pytest.xfail', 'pytest.xfail', ({(507, 21, 507, 77): '"""missing value sorting order not defined for index type"""'}, {}), "('missing value sorting order not defined for index type')", False, 'import pytest\n'), ((510, 13, 510, 83), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((525, 8, 525, 78), 'pytest.xfail', 'pytest.xfail', ({(525, 21, 525, 77): '"""missing value sorting order not defined for index type"""'}, {}), "('missing value sorting order not defined for index type')", False, 'import pytest\n'), ((40, 17, 40, 42), 'pytest.raises', 'pytest.raises', ({(40, 31, 40, 41): 'ValueError'}, {}), '(ValueError)', False, 'import pytest\n'), ((44, 17, 47, 13), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((337, 16, 337, 55), 'pandas._testing.assert_index_equal', 'tm.assert_index_equal', ({(337, 38, 337, 44): 'result', (337, 46, 337, 54): 'expected'}, {}), '(result, expected)', True, 'import pandas._testing as tm\n'), ((390, 17, 390, 42), 'pytest.raises', 'pytest.raises', ({(390, 31, 390, 41): 'ValueError'}, {}), '(ValueError)', False, 'import pytest\n'), ((425, 12, 425, 43), 'pandas.Series', 'pd.Series', ({(425, 22, 425, 42): 'duplicated_selection'}, {}), '(duplicated_selection)', True, 'import pandas as pd\n'), ((430, 34, 430, 48), 'pandas.Series', 'pd.Series', ({(430, 44, 430, 47): 'idx'}, {}), '(idx)', True, 'import pandas as pd\n')]