Skip to content

add_bounds uses keys rather than dims #221

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 2 commits into from
May 3, 2021
Merged

add_bounds uses keys rather than dims #221

merged 2 commits into from
May 3, 2021

Conversation

malmans2
Copy link
Member

@malmans2 malmans2 commented May 1, 2021

No description provided.

@codecov
Copy link

codecov bot commented May 1, 2021

Codecov Report

Merging #221 (2f74c30) into main (e4fa084) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #221   +/-   ##
=======================================
  Coverage   96.45%   96.46%           
=======================================
  Files          12       12           
  Lines        1551     1555    +4     
=======================================
+ Hits         1496     1500    +4     
  Misses         55       55           
Flag Coverage Δ
unittests 96.46% <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 95.36% <100.00%> (+0.01%) ⬆️
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 e4fa084...2f74c30. 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 @malmans2 looks OK, just one minor suggestion. Can you add a whats-new note.

Comment on lines 1615 to 1619
dimensions = set()
for key in keys:
dimensions |= set(
apply_mapper(_get_dims, self._obj, key, error=False, default=[key])
)
Copy link
Contributor

Choose a reason for hiding this comment

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

A set comprehension is cleaner here

Suggested change
dimensions = set()
for key in keys:
dimensions |= set(
apply_mapper(_get_dims, self._obj, key, error=False, default=[key])
)
dimensions = {
apply_mapper(_get_dims, self._obj, key, error=False, default=[key])
for key in keys
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually shouldn't the default be key instead of [key] given that you're doing set subttraction later.

Copy link
Member Author

Choose a reason for hiding this comment

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

apply_mapper returns a list of dimension names, shouldn't default do the same?

Regarding the set comprehension, this wouldn't work: {["dim1", "dim2"], ["dim3"]}.

How about this?

dimensions = {dim for key in keys for dim in apply_mapper(_get_dims, self._obj, key, error=False, default=[key])}

Or we could use update:

dimensions = set()
for key in keys:
    dimensions.update(apply_mapper(_get_dims, self._obj, key, error=False, default=[key]))

Copy link
Contributor

Choose a reason for hiding this comment

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

I like update

@dcherian dcherian merged commit ad3d498 into main May 3, 2021
@dcherian dcherian deleted the add_bounds_keys branch May 3, 2021 19:52
dcherian added a commit to jthielen/cf-xarray that referenced this pull request May 18, 2021
* upstream/main:
  Update README.rst
  Add earthcube 2021 notebook link to readme
  v0.5.2
  Some CMIP6 support
  Add pooch to binder environment (xarray-contrib#223)
  `add_bounds` uses `keys` rather than `dims` (xarray-contrib#221)
dcherian added a commit to jukent/cf-xarray that referenced this pull request Jun 8, 2021
* main: (57 commits)
  Add CITATION.cff, tributors, zenodo.json (xarray-contrib#231)
  Add zenodo badge
  Improve `rename_like` (xarray-contrib#222)
  Don't apply mappers to DataArrays (xarray-contrib#227)
  Add unit support to cf-xarray (xarray-contrib#197)
  Update README.rst
  Add earthcube 2021 notebook link to readme
  v0.5.2
  Some CMIP6 support
  Add pooch to binder environment (xarray-contrib#223)
  `add_bounds` uses `keys` rather than `dims` (xarray-contrib#221)
  Add .cf.formula_terms (xarray-contrib#213)
  Update whats-new.rst (xarray-contrib#217)
  add bounds property (xarray-contrib#214)
  Update some tests.
  Compile regexes
  Fix black
  Add __version__ (xarray-contrib#208)
  add skip to rename_like (xarray-contrib#206)
  Refactor out coordinate criteria to criteria.py (xarray-contrib#205)
  ...
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