Skip to content

CLN: Refactor Index._validate_names() #19171

Open
@spacesphere

Description

@spacesphere

Currently Index._validate_names() does not only validation, but some other unrelated to validation stuff:

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

No one assigned

    Labels

    IndexRelated to the Index class or subclassesInternalsRelated to non-user accessible pandas implementationRefactorInternal refactoring of code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions