Skip to content

rename_like warns about conflicting variables #183

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 9 commits into from
Mar 8, 2021
Merged

rename_like warns about conflicting variables #183

merged 9 commits into from
Mar 8, 2021

Conversation

malmans2
Copy link
Member

Closes #182

@@ -1346,6 +1346,19 @@ def rename_like(
theirs = _single(_get_all)(other, key)[0]
renamer[ours] = theirs
Copy link
Member Author

Choose a reason for hiding this comment

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

Are there weird cases where this is actually a conflict and we should skip and warn about it?

Copy link
Contributor

Choose a reason for hiding this comment

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

no idea ;) lets find out.

@codecov-io
Copy link

codecov-io commented Mar 1, 2021

Codecov Report

Merging #183 (a62f072) into main (7a8c620) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #183      +/-   ##
==========================================
+ Coverage   96.12%   96.13%   +0.01%     
==========================================
  Files          11       11              
  Lines        1366     1372       +6     
==========================================
+ Hits         1313     1319       +6     
  Misses         53       53              
Flag Coverage Δ
unittests 96.13% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
cf_xarray/accessor.py 94.95% <100.00%> (+0.03%) ⬆️
cf_xarray/tests/test_accessor.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7a8c620...a62f072. Read the comment docs.

Copy link
Contributor

@dcherian dcherian left a comment

Choose a reason for hiding this comment

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

Thanks Mattia.

It'd be nice if there was a way for the user to limit the renaming in some form but maybe this should be a future PR

pop.cf["TEMP"].cf.rename_like(ds, do=["coordinates", "standard_name"])

This would work, since it would skip nlon, nlat so there would be no conflicts.

Likewise

pop.cf["TEMP"].cf.rename_like(ds, do=["axes"])

woudl rename nlon, nlat to lon, lat

@@ -1346,6 +1346,19 @@ def rename_like(
theirs = _single(_get_all)(other, key)[0]
renamer[ours] = theirs
Copy link
Contributor

Choose a reason for hiding this comment

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

no idea ;) lets find out.

@@ -1340,12 +1340,36 @@ def rename_like(
theirkeys = other.cf.keys()

good_keys = ourkeys & theirkeys
renamer = {}
keydict = {}
for key in good_keys:
ours = _single(_get_all)(self._obj, key)[0]
Copy link
Member Author

@malmans2 malmans2 Mar 5, 2021

Choose a reason for hiding this comment

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

Should we catch the error from _single and just skip+warn?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes that sounds right

@malmans2
Copy link
Member Author

malmans2 commented Mar 5, 2021

Looks like this now:

from cf_xarray.datasets import airds, popds
popds.cf.rename_like(airds)
UserWarning: Conflicting variables skipped:
['TLAT', 'ULAT']: ['lat'] (latitude)
['TLONG', 'ULONG']: ['lon'] (longitude)
['nlat']: ['lat'] (Y)
['nlon']: ['lon'] (X)

@dcherian
Copy link
Contributor

dcherian commented Mar 8, 2021

Thanks @malmans2

@dcherian dcherian merged commit 1408f5d into main Mar 8, 2021
@dcherian dcherian deleted the fix_docs branch March 8, 2021 15:12
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.

Documentation notebook is broken
3 participants