Skip to content

Clean names multiindex #11

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

Merged
merged 3 commits into from
Mar 22, 2018

Conversation

JoshuaC3
Copy link
Contributor

Change cleaan_names so that it works for MultiIndexes and also add tests for this.

Fixes #10

.replace('.', '_')
)

df = df.rename(columns=lambda x: re.sub('_+', '_', x))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff!

df = pd.DataFrame(data)
return df


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful, thanks for following the programming pattern!

labels = [[0, 1, 2], [0, 1, 2]]

expected_columns = pd.MultiIndex(levels=levels, labels=labels)
assert set(df.columns) == set(expected_columns)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, you really went above-and-beyond here! Thanks for doing this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - My only thought on this was, should we be handling levels, labels and maybe expected_columns at a global level so that I am not just repeating the setup of variables? I am not experienced with writing test so I am not sure what is good or standard practice.

@ericmjl
Copy link
Member

ericmjl commented Mar 22, 2018

Thanks for your contribution, @JoshuaC3! I am going to merge.

@ericmjl ericmjl merged commit b87257e into pyjanitor-devs:master Mar 22, 2018
@JoshuaC3
Copy link
Contributor Author

Thank you for the positive feedback. I learnt a lot contributing here.

There are some other parts I that I think could be improved. I will raise some issues for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants