|
| 1 | +from functools import wraps |
1 | 2 | from sys import getsizeof
|
2 | 3 | from typing import (
|
3 | 4 | TYPE_CHECKING,
|
@@ -152,6 +153,25 @@ def _codes_to_ints(self, codes):
|
152 | 153 | return np.bitwise_or.reduce(codes, axis=1)
|
153 | 154 |
|
154 | 155 |
|
| 156 | +def names_compat(meth): |
| 157 | + """ |
| 158 | + A decorator to allow either `name` or `names` keyword but not both. |
| 159 | +
|
| 160 | + This makes it easier to share code with base class. |
| 161 | + """ |
| 162 | + |
| 163 | + @wraps(meth) |
| 164 | + def new_meth(self_or_cls, *args, **kwargs): |
| 165 | + if "name" in kwargs and "names" in kwargs: |
| 166 | + raise TypeError("Can only provide one of `names` and `name`") |
| 167 | + elif "name" in kwargs: |
| 168 | + kwargs["names"] = kwargs.pop("name") |
| 169 | + |
| 170 | + return meth(self_or_cls, *args, **kwargs) |
| 171 | + |
| 172 | + return new_meth |
| 173 | + |
| 174 | + |
155 | 175 | class MultiIndex(Index):
|
156 | 176 | """
|
157 | 177 | A multi-level, or hierarchical, index object for pandas objects.
|
@@ -449,6 +469,7 @@ def from_arrays(cls, arrays, sortorder=None, names=lib.no_default) -> "MultiInde
|
449 | 469 | )
|
450 | 470 |
|
451 | 471 | @classmethod
|
| 472 | + @names_compat |
452 | 473 | def from_tuples(
|
453 | 474 | cls,
|
454 | 475 | tuples,
|
@@ -3635,10 +3656,6 @@ def delete(self, loc):
|
3635 | 3656 | verify_integrity=False,
|
3636 | 3657 | )
|
3637 | 3658 |
|
3638 |
| - def _wrap_joined_index(self, joined, other): |
3639 |
| - names = self.names if self.names == other.names else None |
3640 |
| - return self._constructor(joined, names=names) |
3641 |
| - |
3642 | 3659 | @doc(Index.isin)
|
3643 | 3660 | def isin(self, values, level=None):
|
3644 | 3661 | if level is None:
|
|
0 commit comments