Skip to content

Commit d032652

Browse files
authored
DEPR: enforce deprecation MultiIndex.is_lexsorted and MultiIndex.lexsort_depth (#49260)
1 parent d00928e commit d032652

File tree

6 files changed

+11
-46
lines changed

6 files changed

+11
-46
lines changed

doc/source/whatsnew/v0.15.2.rst

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ API changes
2525
a lexically sorted index will have a better performance. (:issue:`2646`)
2626

2727
.. ipython:: python
28+
:okexcept:
2829
:okwarning:
2930
3031
df = pd.DataFrame({'jim':[0, 0, 1, 1],

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ Removal of prior version deprecations/changes
177177
- Remove arguments ``names`` and ``dtype`` from :meth:`Index.copy` and ``levels`` and ``codes`` from :meth:`MultiIndex.copy` (:issue:`35853`, :issue:`36685`)
178178
- Remove argument ``inplace`` from :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`35626`)
179179
- Disallow passing positional arguments to :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`41485`)
180+
- Removed :meth:`MultiIndex.is_lexsorted` and :meth:`MultiIndex.lexsort_depth` (:issue:`38701`)
180181
- Removed argument ``how`` from :meth:`PeriodIndex.astype`, use :meth:`PeriodIndex.to_timestamp` instead (:issue:`37982`)
181182
- Removed argument ``try_cast`` from :meth:`DataFrame.mask`, :meth:`DataFrame.where`, :meth:`Series.mask` and :meth:`Series.where` (:issue:`38836`)
182183
- Removed argument ``is_copy`` from :meth:`DataFrame.take` and :meth:`Series.take` (:issue:`30615`)

pandas/conftest.py

-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ def pytest_collection_modifyitems(items, config) -> None:
154154
("DataFrame.append", "The frame.append method is deprecated"),
155155
("Series.append", "The series.append method is deprecated"),
156156
("dtypes.common.is_categorical", "is_categorical is deprecated"),
157-
("MultiIndex._is_lexsorted", "MultiIndex.is_lexsorted is deprecated"),
158157
# Docstring divides by zero to show behavior difference
159158
("missing.mask_zero_div_zero", "divide by zero encountered"),
160159
# Docstring demonstrates the call raises a warning

pandas/core/indexes/multi.py

+8-25
Original file line numberDiff line numberDiff line change
@@ -1810,15 +1810,6 @@ def to_flat_index(self) -> Index: # type: ignore[override]
18101810
"""
18111811
return Index(self._values, tupleize_cols=False)
18121812

1813-
def is_lexsorted(self) -> bool:
1814-
warnings.warn(
1815-
"MultiIndex.is_lexsorted is deprecated as a public function, "
1816-
"users should use MultiIndex.is_monotonic_increasing instead.",
1817-
FutureWarning,
1818-
stacklevel=find_stack_level(),
1819-
)
1820-
return self._is_lexsorted()
1821-
18221813
def _is_lexsorted(self) -> bool:
18231814
"""
18241815
Return True if the codes are lexicographically sorted.
@@ -1832,37 +1823,29 @@ def _is_lexsorted(self) -> bool:
18321823
In the below examples, the first level of the MultiIndex is sorted because
18331824
a<b<c, so there is no need to look at the next level.
18341825
1835-
>>> pd.MultiIndex.from_arrays([['a', 'b', 'c'], ['d', 'e', 'f']]).is_lexsorted()
1826+
>>> pd.MultiIndex.from_arrays([['a', 'b', 'c'],
1827+
... ['d', 'e', 'f']])._is_lexsorted()
18361828
True
1837-
>>> pd.MultiIndex.from_arrays([['a', 'b', 'c'], ['d', 'f', 'e']]).is_lexsorted()
1829+
>>> pd.MultiIndex.from_arrays([['a', 'b', 'c'],
1830+
... ['d', 'f', 'e']])._is_lexsorted()
18381831
True
18391832
18401833
In case there is a tie, the lexicographical sorting looks
18411834
at the next level of the MultiIndex.
18421835
1843-
>>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'b', 'c']]).is_lexsorted()
1836+
>>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'b', 'c']])._is_lexsorted()
18441837
True
1845-
>>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'c', 'b']]).is_lexsorted()
1838+
>>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'c', 'b']])._is_lexsorted()
18461839
False
18471840
>>> pd.MultiIndex.from_arrays([['a', 'a', 'b', 'b'],
1848-
... ['aa', 'bb', 'aa', 'bb']]).is_lexsorted()
1841+
... ['aa', 'bb', 'aa', 'bb']])._is_lexsorted()
18491842
True
18501843
>>> pd.MultiIndex.from_arrays([['a', 'a', 'b', 'b'],
1851-
... ['bb', 'aa', 'aa', 'bb']]).is_lexsorted()
1844+
... ['bb', 'aa', 'aa', 'bb']])._is_lexsorted()
18521845
False
18531846
"""
18541847
return self._lexsort_depth == self.nlevels
18551848

1856-
@property
1857-
def lexsort_depth(self) -> int:
1858-
warnings.warn(
1859-
"MultiIndex.lexsort_depth is deprecated as a public function, "
1860-
"users should use MultiIndex.is_monotonic_increasing instead.",
1861-
FutureWarning,
1862-
stacklevel=find_stack_level(),
1863-
)
1864-
return self._lexsort_depth
1865-
18661849
@cache_readonly
18671850
def _lexsort_depth(self) -> int:
18681851
"""

pandas/tests/indexes/multi/test_lexsort.py

-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from pandas import MultiIndex
2-
import pandas._testing as tm
32

43

54
class TestIsLexsorted:
@@ -22,14 +21,6 @@ def test_is_lexsorted(self):
2221
assert not index._is_lexsorted()
2322
assert index._lexsort_depth == 0
2423

25-
def test_is_lexsorted_deprecation(self):
26-
# GH 32259
27-
with tm.assert_produces_warning(
28-
FutureWarning,
29-
match="MultiIndex.is_lexsorted is deprecated as a public function",
30-
):
31-
MultiIndex.from_arrays([["a", "b", "c"], ["d", "f", "e"]]).is_lexsorted()
32-
3324

3425
class TestLexsortDepth:
3526
def test_lexsort_depth(self):
@@ -53,11 +44,3 @@ def test_lexsort_depth(self):
5344
levels=levels, codes=[[0, 0, 1, 0, 1, 1], [0, 1, 0, 2, 2, 1]], sortorder=0
5445
)
5546
assert index._lexsort_depth == 0
56-
57-
def test_lexsort_depth_deprecation(self):
58-
# GH 32259
59-
with tm.assert_produces_warning(
60-
FutureWarning,
61-
match="MultiIndex.lexsort_depth is deprecated as a public function",
62-
):
63-
MultiIndex.from_arrays([["a", "b", "c"], ["d", "f", "e"]]).lexsort_depth

pandas/tests/indexes/multi/test_setops.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -683,9 +683,7 @@ def test_intersection_lexsort_depth(levels1, levels2, codes1, codes2, names):
683683
mi1 = MultiIndex(levels=levels1, codes=codes1, names=names)
684684
mi2 = MultiIndex(levels=levels2, codes=codes2, names=names)
685685
mi_int = mi1.intersection(mi2)
686-
687-
with tm.assert_produces_warning(FutureWarning, match="MultiIndex.lexsort_depth"):
688-
assert mi_int.lexsort_depth == 2
686+
assert mi_int._lexsort_depth == 2
689687

690688

691689
@pytest.mark.parametrize("val", [pd.NA, 100])

0 commit comments

Comments
 (0)