Skip to content

Fix inconsistent behaviour for xarray.DataArray.rename #1178

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 5 commits into from
Dec 23, 2016

Conversation

magonser
Copy link
Contributor

Attempt to fix #1177

Please let me know, if PR requires further refinement.

@magonser magonser changed the title Changes DataArray.rename to a more explicit behavior. Attempt to fix #1177 Dec 21, 2016
names to new names for coordinates. Otherwise, use the argument
as the new name for this array.

new_dims_dict : dict-like
Copy link
Member

Choose a reason for hiding this comment

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

Instead of adding a second argument here, I would simply require calling .rename() twice if you want to rename both the DataArray and it's coordinates at the same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've been thinking about that initially, too. Fixed in f855063.

@shoyer shoyer changed the title Attempt to fix #1177 Fix inconsistent behaviour for xarray.DataArray.rename Dec 21, 2016
@@ -788,16 +788,17 @@ def reindex(self, method=None, tolerance=None, copy=True, **indexers):
method=method, tolerance=tolerance, copy=copy, **indexers)
return self._from_temp_dataset(ds)

def rename(self, new_name_or_name_dict):
"""Returns a new DataArray with renamed coordinates and/or a new name.
def rename(self, new_name_or_dims_dict):
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep this parameter name the same as before.

Copy link
Member

@shoyer shoyer left a comment

Choose a reason for hiding this comment

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

Looks good to me. I'll keep this only for a little while in case anyone else wants to chime in.

@@ -811,12 +812,8 @@ def rename(self, new_name_or_name_dict):
"""
if utils.is_dict_like(new_name_or_name_dict):
name_dict = new_name_or_name_dict.copy()
Copy link
Member

Choose a reason for hiding this comment

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

It occurs to me that the copying here is no longer necessary, since we no longer modify the dictionary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have pushed another commit fa6b02c to remove it. Keeping the PR open for another while is fine by me.

@fmaussion
Copy link
Member

Slightly OT, but it occurred to me that we took the habit not to add an attribution (e.g. "By bla") to the "Breaking changes" list. This is probably nicer for the people who are quickly reading through the changes, but not really consistent with the bugfixes or enhancements.

In that case, I think you could list your change in the "bugfix" list rather than "breaking changes"

@shoyer
Copy link
Member

shoyer commented Dec 23, 2016

@fmaussion that was my mistake here -- I didn't give myself credit on a few of the "Breaking Changes" but we should fix that.

@magonser want to insert a line giving yourself credit for this change?

@magonser
Copy link
Contributor Author

Alright, I've added attribution. Thanks by the way for being patient with me in this PR, as I am just getting started on open source contributions.

@shoyer shoyer merged commit bb12c69 into pydata:master Dec 23, 2016
@shoyer
Copy link
Member

shoyer commented Dec 23, 2016

Thanks @magonser, we really appreciate PRs, especially from new contributors!

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.

Inconsistent behaviour for xarray.DataArray.rename
3 participants