-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Open
Labels
IndexRelated to the Index class or subclassesRelated to the Index class or subclassesInternalsRelated to non-user accessible pandas implementationRelated to non-user accessible pandas implementationRefactorInternal refactoring of codeInternal refactoring of code
Description
Currently Index._validate_names()
does not only validation, but some other unrelated to validation stuff:
pandas/pandas/core/indexes/base.py
Lines 803 to 820 in 055bfa6
def _validate_names(self, name=None, names=None, deep=False): | |
""" | |
Handles the quirks of having a singular 'name' parameter for general | |
Index and plural 'names' parameter for MultiIndex. | |
""" | |
from copy import deepcopy | |
if names is not None and name is not None: | |
raise TypeError("Can only provide one of `names` and `name`") | |
elif names is None and name is None: | |
return deepcopy(self.names) if deep else self.names | |
elif names is not None: | |
if not is_list_like(names): | |
raise TypeError("Must pass list-like as `names`.") | |
return names | |
else: | |
if not is_list_like(name): | |
return [name] | |
return name |
Moreover, it's closely tied in with copying logic without any reason, so that _validate_names()
cannot be used in other cases.
I think it would be reasonable to separate these responsibilities.
Metadata
Metadata
Assignees
Labels
IndexRelated to the Index class or subclassesRelated to the Index class or subclassesInternalsRelated to non-user accessible pandas implementationRelated to non-user accessible pandas implementationRefactorInternal refactoring of codeInternal refactoring of code