Skip to content
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

CLN: Refactor Index._validate_names() #19171

Open
spacesphere opened this issue Jan 10, 2018 · 2 comments
Open

CLN: Refactor Index._validate_names() #19171

spacesphere opened this issue Jan 10, 2018 · 2 comments
Labels
Index Related to the Index class or subclasses Internals Related to non-user accessible pandas implementation Refactor Internal refactoring of code

Comments

@spacesphere
Copy link
Contributor

spacesphere commented Jan 10, 2018

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.

@gfyoung gfyoung added Indexing Related to indexing on series/frames, not to indexes themselves Internals Related to non-user accessible pandas implementation labels Jan 12, 2018
@gfyoung
Copy link
Member

gfyoung commented Jan 12, 2018

@PoppyBagel : Thanks for reporting this! Perhaps the name is a little misleading, as you're indeed correct that we don't just validate. Maybe a name like "_parse_names" might be more appropriate. Feel free to propose another name in a PR if you like.

@jreback jreback added this to the 0.23.0 milestone Jan 15, 2018
@jreback jreback modified the milestones: 0.23.0, Next Major Release Apr 14, 2018
@jbrockmendel jbrockmendel added Index Related to the Index class or subclasses and removed Indexing Related to indexing on series/frames, not to indexes themselves labels Feb 10, 2020
@mroeschke mroeschke added the Refactor Internal refactoring of code label Apr 27, 2020
@jbrockmendel
Copy link
Member

Probably becomes simpler once #44916 is enforced.

@jbrockmendel jbrockmendel modified the milestones: Contributions Welcome, 2.0 Dec 21, 2021
@mroeschke mroeschke removed this from the 2.0 milestone Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Index Related to the Index class or subclasses Internals Related to non-user accessible pandas implementation Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants