-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
DEPR: MultiIndex.to_hierarchical, labels #29766
Changes from all commits
2d3e009
68ea192
042d394
e22ba3f
a98c259
0a0de52
5e0aae4
fecb434
c2e9f14
bb15c47
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 |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
"odfpy": "1.3.0", | ||
"openpyxl": "2.4.8", | ||
"pandas_gbq": "0.8.0", | ||
"pyarrow": "0.9.0", | ||
"pyarrow": "0.12.0", | ||
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. @datapythonista here we need to update pytest 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. Thanks for the clarification, I found it. It's already implemented in #29782 |
||
"pytables": "3.4.2", | ||
"pytest": "5.0.1", | ||
"s3fs": "0.3.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,6 +160,12 @@ def _new_Index(cls, d): | |
from pandas.core.indexes.period import _new_PeriodIndex | ||
|
||
return _new_PeriodIndex(cls, **d) | ||
|
||
if issubclass(cls, ABCMultiIndex): | ||
if "labels" in d and "codes" not in d: | ||
# GH#23752 "labels" kwarg has been replaced with "codes" | ||
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. do we have an issue about removing this code at some point, what are the pre-conditions for that? 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.
not wanting/needing to support sufficiently-old pickles 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. can you clarify, meaning < 0.23.4? later? (if you can pls put in the issue) |
||
d["codes"] = d.pop("labels") | ||
simonjayhawkins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return cls.__new__(cls, **d) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
from pandas._libs.hashtable import duplicated_int64 | ||
from pandas.compat.numpy import function as nv | ||
from pandas.errors import PerformanceWarning, UnsortedIndexError | ||
from pandas.util._decorators import Appender, cache_readonly, deprecate_kwarg | ||
from pandas.util._decorators import Appender, cache_readonly | ||
|
||
from pandas.core.dtypes.common import ( | ||
ensure_int64, | ||
|
@@ -229,9 +229,7 @@ class MultiIndex(Index): | |
of the mentioned helper methods. | ||
""" | ||
|
||
_deprecations = Index._deprecations | frozenset( | ||
["labels", "set_labels", "to_hierarchical"] | ||
) | ||
_deprecations = Index._deprecations | frozenset() | ||
|
||
# initialize to zero-length tuples to make everything work | ||
_typ = "multiindex" | ||
|
@@ -244,7 +242,6 @@ class MultiIndex(Index): | |
# -------------------------------------------------------------------- | ||
# Constructors | ||
|
||
@deprecate_kwarg(old_arg_name="labels", new_arg_name="codes") | ||
def __new__( | ||
cls, | ||
levels=None, | ||
|
@@ -813,15 +810,6 @@ def set_levels(self, levels, level=None, inplace=False, verify_integrity=True): | |
def codes(self): | ||
return self._codes | ||
|
||
@property | ||
def labels(self): | ||
warnings.warn( | ||
(".labels was deprecated in version 0.24.0. Use .codes instead."), | ||
FutureWarning, | ||
stacklevel=2, | ||
) | ||
return self.codes | ||
|
||
def _set_codes( | ||
self, codes, level=None, copy=False, validate=True, verify_integrity=False | ||
): | ||
|
@@ -854,23 +842,6 @@ def _set_codes( | |
self._tuples = None | ||
self._reset_cache() | ||
|
||
def set_labels(self, labels, level=None, inplace=False, verify_integrity=True): | ||
warnings.warn( | ||
( | ||
".set_labels was deprecated in version 0.24.0. " | ||
"Use .set_codes instead." | ||
), | ||
FutureWarning, | ||
stacklevel=2, | ||
) | ||
return self.set_codes( | ||
codes=labels, | ||
level=level, | ||
inplace=inplace, | ||
verify_integrity=verify_integrity, | ||
) | ||
|
||
@deprecate_kwarg(old_arg_name="labels", new_arg_name="codes") | ||
def set_codes(self, codes, level=None, inplace=False, verify_integrity=True): | ||
""" | ||
Set new codes on MultiIndex. Defaults to returning | ||
|
@@ -947,7 +918,6 @@ def set_codes(self, codes, level=None, inplace=False, verify_integrity=True): | |
if not inplace: | ||
return idx | ||
|
||
@deprecate_kwarg(old_arg_name="labels", new_arg_name="codes") | ||
def copy( | ||
self, | ||
names=None, | ||
|
@@ -981,7 +951,8 @@ def copy( | |
""" | ||
name = kwargs.get("name") | ||
names = self._validate_names(name=name, names=names, deep=deep) | ||
|
||
if "labels" in kwargs: | ||
raise TypeError("'labels' argument has been removed; use 'codes' instead") | ||
Comment on lines
+954
to
+955
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. same 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. ideally i think we should just get kwargs out of the signature of this function, but im fine with adding a test for this in the interim |
||
if deep: | ||
from copy import deepcopy | ||
|
||
|
@@ -1700,62 +1671,6 @@ def to_frame(self, index=True, name=None): | |
result.index = self | ||
return result | ||
|
||
def to_hierarchical(self, n_repeat, n_shuffle=1): | ||
""" | ||
Return a MultiIndex reshaped to conform to the | ||
shapes given by n_repeat and n_shuffle. | ||
|
||
.. deprecated:: 0.24.0 | ||
|
||
Useful to replicate and rearrange a MultiIndex for combination | ||
with another Index with n_repeat items. | ||
|
||
Parameters | ||
---------- | ||
n_repeat : int | ||
Number of times to repeat the labels on self. | ||
n_shuffle : int | ||
Controls the reordering of the labels. If the result is going | ||
to be an inner level in a MultiIndex, n_shuffle will need to be | ||
greater than one. The size of each label must divisible by | ||
n_shuffle. | ||
|
||
Returns | ||
------- | ||
MultiIndex | ||
|
||
Examples | ||
-------- | ||
>>> idx = pd.MultiIndex.from_tuples([(1, 'one'), (1, 'two'), | ||
(2, 'one'), (2, 'two')]) | ||
>>> idx.to_hierarchical(3) | ||
MultiIndex([(1, 'one'), | ||
(1, 'one'), | ||
(1, 'one'), | ||
(1, 'two'), | ||
(1, 'two'), | ||
(1, 'two'), | ||
(2, 'one'), | ||
(2, 'one'), | ||
(2, 'one'), | ||
(2, 'two'), | ||
(2, 'two'), | ||
(2, 'two')], | ||
) | ||
""" | ||
levels = self.levels | ||
codes = [np.repeat(level_codes, n_repeat) for level_codes in self.codes] | ||
# Assumes that each level_codes is divisible by n_shuffle | ||
codes = [x.reshape(n_shuffle, -1).ravel(order="F") for x in codes] | ||
names = self.names | ||
warnings.warn( | ||
"Method .to_hierarchical is deprecated and will " | ||
"be removed in a future version", | ||
FutureWarning, | ||
stacklevel=2, | ||
) | ||
return MultiIndex(levels=levels, codes=codes, names=names) | ||
|
||
def to_flat_index(self): | ||
""" | ||
Convert a MultiIndex to an Index of Tuples containing the level values. | ||
|
@@ -2148,7 +2063,6 @@ def repeat(self, repeats, axis=None): | |
def where(self, cond, other=None): | ||
raise NotImplementedError(".where is not supported for MultiIndex operations") | ||
|
||
@deprecate_kwarg(old_arg_name="labels", new_arg_name="codes") | ||
def drop(self, codes, level=None, errors="raise"): | ||
""" | ||
Make new MultiIndex with passed list of codes deleted | ||
|
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.
can you update this to 5.0.1 with an X next time you change something in whatsnew, cc @datapythonista