diff --git a/doc/source/whatsnew/v0.15.2.rst b/doc/source/whatsnew/v0.15.2.rst index 2dae76dd6b461..fd4946c9765e1 100644 --- a/doc/source/whatsnew/v0.15.2.rst +++ b/doc/source/whatsnew/v0.15.2.rst @@ -25,6 +25,7 @@ API changes a lexically sorted index will have a better performance. (:issue:`2646`) .. ipython:: python + :okexcept: :okwarning: df = pd.DataFrame({'jim':[0, 0, 1, 1], diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 6239ddf9442e7..2ba3bd9470ff3 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -177,6 +177,7 @@ Removal of prior version deprecations/changes - Remove arguments ``names`` and ``dtype`` from :meth:`Index.copy` and ``levels`` and ``codes`` from :meth:`MultiIndex.copy` (:issue:`35853`, :issue:`36685`) - Remove argument ``inplace`` from :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`35626`) - Disallow passing positional arguments to :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`41485`) +- Removed :meth:`MultiIndex.is_lexsorted` and :meth:`MultiIndex.lexsort_depth` (:issue:`38701`) - Removed argument ``how`` from :meth:`PeriodIndex.astype`, use :meth:`PeriodIndex.to_timestamp` instead (:issue:`37982`) - Removed argument ``try_cast`` from :meth:`DataFrame.mask`, :meth:`DataFrame.where`, :meth:`Series.mask` and :meth:`Series.where` (:issue:`38836`) - Removed argument ``is_copy`` from :meth:`DataFrame.take` and :meth:`Series.take` (:issue:`30615`) diff --git a/pandas/conftest.py b/pandas/conftest.py index d9f481d843b37..24d878cf1cde9 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -154,7 +154,6 @@ def pytest_collection_modifyitems(items, config) -> None: ("DataFrame.append", "The frame.append method is deprecated"), ("Series.append", "The series.append method is deprecated"), ("dtypes.common.is_categorical", "is_categorical is deprecated"), - ("MultiIndex._is_lexsorted", "MultiIndex.is_lexsorted is deprecated"), # Docstring divides by zero to show behavior difference ("missing.mask_zero_div_zero", "divide by zero encountered"), # Docstring demonstrates the call raises a warning diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 59a0179f93c10..761869d2b5954 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1810,15 +1810,6 @@ def to_flat_index(self) -> Index: # type: ignore[override] """ return Index(self._values, tupleize_cols=False) - def is_lexsorted(self) -> bool: - warnings.warn( - "MultiIndex.is_lexsorted is deprecated as a public function, " - "users should use MultiIndex.is_monotonic_increasing instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - return self._is_lexsorted() - def _is_lexsorted(self) -> bool: """ Return True if the codes are lexicographically sorted. @@ -1832,37 +1823,29 @@ def _is_lexsorted(self) -> bool: In the below examples, the first level of the MultiIndex is sorted because a>> pd.MultiIndex.from_arrays([['a', 'b', 'c'], ['d', 'e', 'f']]).is_lexsorted() + >>> pd.MultiIndex.from_arrays([['a', 'b', 'c'], + ... ['d', 'e', 'f']])._is_lexsorted() True - >>> pd.MultiIndex.from_arrays([['a', 'b', 'c'], ['d', 'f', 'e']]).is_lexsorted() + >>> pd.MultiIndex.from_arrays([['a', 'b', 'c'], + ... ['d', 'f', 'e']])._is_lexsorted() True In case there is a tie, the lexicographical sorting looks at the next level of the MultiIndex. - >>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'b', 'c']]).is_lexsorted() + >>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'b', 'c']])._is_lexsorted() True - >>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'c', 'b']]).is_lexsorted() + >>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'c', 'b']])._is_lexsorted() False >>> pd.MultiIndex.from_arrays([['a', 'a', 'b', 'b'], - ... ['aa', 'bb', 'aa', 'bb']]).is_lexsorted() + ... ['aa', 'bb', 'aa', 'bb']])._is_lexsorted() True >>> pd.MultiIndex.from_arrays([['a', 'a', 'b', 'b'], - ... ['bb', 'aa', 'aa', 'bb']]).is_lexsorted() + ... ['bb', 'aa', 'aa', 'bb']])._is_lexsorted() False """ return self._lexsort_depth == self.nlevels - @property - def lexsort_depth(self) -> int: - warnings.warn( - "MultiIndex.lexsort_depth is deprecated as a public function, " - "users should use MultiIndex.is_monotonic_increasing instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - return self._lexsort_depth - @cache_readonly def _lexsort_depth(self) -> int: """ diff --git a/pandas/tests/indexes/multi/test_lexsort.py b/pandas/tests/indexes/multi/test_lexsort.py index 0aadbdb5c32da..fc16a4197a3a4 100644 --- a/pandas/tests/indexes/multi/test_lexsort.py +++ b/pandas/tests/indexes/multi/test_lexsort.py @@ -1,5 +1,4 @@ from pandas import MultiIndex -import pandas._testing as tm class TestIsLexsorted: @@ -22,14 +21,6 @@ def test_is_lexsorted(self): assert not index._is_lexsorted() assert index._lexsort_depth == 0 - def test_is_lexsorted_deprecation(self): - # GH 32259 - with tm.assert_produces_warning( - FutureWarning, - match="MultiIndex.is_lexsorted is deprecated as a public function", - ): - MultiIndex.from_arrays([["a", "b", "c"], ["d", "f", "e"]]).is_lexsorted() - class TestLexsortDepth: def test_lexsort_depth(self): @@ -53,11 +44,3 @@ def test_lexsort_depth(self): levels=levels, codes=[[0, 0, 1, 0, 1, 1], [0, 1, 0, 2, 2, 1]], sortorder=0 ) assert index._lexsort_depth == 0 - - def test_lexsort_depth_deprecation(self): - # GH 32259 - with tm.assert_produces_warning( - FutureWarning, - match="MultiIndex.lexsort_depth is deprecated as a public function", - ): - MultiIndex.from_arrays([["a", "b", "c"], ["d", "f", "e"]]).lexsort_depth diff --git a/pandas/tests/indexes/multi/test_setops.py b/pandas/tests/indexes/multi/test_setops.py index 61e602f4c41fe..eaa4e0a7b5256 100644 --- a/pandas/tests/indexes/multi/test_setops.py +++ b/pandas/tests/indexes/multi/test_setops.py @@ -683,9 +683,7 @@ def test_intersection_lexsort_depth(levels1, levels2, codes1, codes2, names): mi1 = MultiIndex(levels=levels1, codes=codes1, names=names) mi2 = MultiIndex(levels=levels2, codes=codes2, names=names) mi_int = mi1.intersection(mi2) - - with tm.assert_produces_warning(FutureWarning, match="MultiIndex.lexsort_depth"): - assert mi_int.lexsort_depth == 2 + assert mi_int._lexsort_depth == 2 @pytest.mark.parametrize("val", [pd.NA, 100])