-
-
Couldn't load subscription status.
- Fork 19.2k
DEPR MultiIndex.is_lexsorted and MultiIndex.lexsort_depth #38701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 16 commits
b5d157a
8ca3b3d
109c1ce
238b568
893ab7c
b2b1c36
b8bcc5e
4ab8981
72b0abc
a0a709c
be2a692
7d1d279
b3c5144
39d163f
6b9c698
74d8c7e
3798cf5
dfc779d
fdbb366
fff7297
fe4aaa6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -391,11 +391,11 @@ def _verify_integrity( | |||||||||||||||
| f"Level values must be unique: {list(level)} on level {i}" | ||||||||||||||||
| ) | ||||||||||||||||
| if self.sortorder is not None: | ||||||||||||||||
| if self.sortorder > self._lexsort_depth(): | ||||||||||||||||
| if self.sortorder > self._codes_lexsort_depth(): | ||||||||||||||||
| raise ValueError( | ||||||||||||||||
| "Value for sortorder must be inferior or equal to actual " | ||||||||||||||||
| f"lexsort_depth: sortorder {self.sortorder} " | ||||||||||||||||
| f"with lexsort_depth {self._lexsort_depth()}" | ||||||||||||||||
| f"with lexsort_depth {self._codes_lexsort_depth()}" | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| codes = [ | ||||||||||||||||
|
|
@@ -1809,6 +1809,15 @@ def _is_all_dates(self) -> bool: | |||||||||||||||
| return 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=2, | ||||||||||||||||
| ) | ||||||||||||||||
| return self._is_lexsorted() | ||||||||||||||||
|
|
||||||||||||||||
| def _is_lexsorted(self) -> bool: | ||||||||||||||||
| """ | ||||||||||||||||
| Return True if the codes are lexicographically sorted. | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -1840,15 +1849,19 @@ def is_lexsorted(self) -> bool: | |||||||||||||||
| ... ['bb', 'aa', 'aa', 'bb']]).is_lexsorted() | ||||||||||||||||
| False | ||||||||||||||||
| """ | ||||||||||||||||
| return self.lexsort_depth == self.nlevels | ||||||||||||||||
| return self._lexsort_depth == self.nlevels | ||||||||||||||||
|
|
||||||||||||||||
| @cache_readonly | ||||||||||||||||
| def lexsort_depth(self): | ||||||||||||||||
| if self.sortorder is not None: | ||||||||||||||||
| return self.sortorder | ||||||||||||||||
|
|
||||||||||||||||
| return self._lexsort_depth() | ||||||||||||||||
| warnings.warn( | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. metion in the whatsnew as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need the cache on this one (as its already on _lexsort_depth) and this is now user facing |
||||||||||||||||
| "MultiIndex.is_lexsorted is deprecated as a public function, " | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MarcoGorelli should the message here refer to lexsort_depth instead of is_lexsorted? this warning isn't being caught in a bunch of tests; not sure why that isn't caught by the npdev build There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, looks like a typo, thanks for catching - we probably want to always use
not sure what you mean here sorry |
||||||||||||||||
| "users should use MultiIndex.is_monotonic_increasing instead.", | ||||||||||||||||
| FutureWarning, | ||||||||||||||||
| stacklevel=2, | ||||||||||||||||
| ) | ||||||||||||||||
| return self._lexsort_depth | ||||||||||||||||
|
|
||||||||||||||||
| @cache_readonly | ||||||||||||||||
| def _lexsort_depth(self) -> int: | ||||||||||||||||
| """ | ||||||||||||||||
| Compute and return the lexsort_depth, the number of levels of the | ||||||||||||||||
|
|
@@ -1858,6 +1871,11 @@ def _lexsort_depth(self) -> int: | |||||||||||||||
| ------- | ||||||||||||||||
| int | ||||||||||||||||
| """ | ||||||||||||||||
| if self.sortorder is not None: | ||||||||||||||||
| return self.sortorder | ||||||||||||||||
| return self._codes_lexsort_depth() | ||||||||||||||||
|
|
||||||||||||||||
| def _codes_lexsort_depth(self) -> int: | ||||||||||||||||
|
||||||||||||||||
| if self.sortorder is not None: | |
| if self.sortorder > self._lexsort_depth(): | |
| raise ValueError( | |
| "Value for sortorder must be inferior or equal to actual " | |
| f"lexsort_depth: sortorder {self.sortorder} " | |
| f"with lexsort_depth {self._lexsort_depth()}" | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made it a module-level function, is this clearer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something went wrong with pasting the indents here, will fix it in the next commit