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

Add ._copy method and _bounds attr to DataArrayBoundsAccessor #98

Merged
merged 1 commit into from
Aug 25, 2021

Conversation

tomvothecoder
Copy link
Collaborator

@tomvothecoder tomvothecoder commented Aug 24, 2021

Description

This PR removes adding the bounds dimension and bounds variables (as coordinates) to the DataArray in DataArrayBoundsAccessor. Instead, a separate _bounds dataset stores the bounds. The advantage of using a dataset is that we can leverage methods of cf_xarray and DatasetBoundsAccessor.

To retain the attributes of an accessor class when copying a variable, each class must have a .copy() method to return a copy of the xarray data structure with cached attributes. There is also a copy_variable() function to handle this for the user so they don't have to invoke each of the individual .copy() methods themself.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

If applicable:

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass with my changes (locally and CI/CD build)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have noted that this is a breaking change for a major release (fix or feature that would cause existing functionality to not work as expected)

@tomvothecoder tomvothecoder added type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors. Priority: High labels Aug 24, 2021
@tomvothecoder tomvothecoder added this to the v1.0.0 milestone Aug 24, 2021
@tomvothecoder tomvothecoder self-assigned this Aug 24, 2021
@codecov
Copy link

codecov bot commented Aug 24, 2021

Codecov Report

Merging #98 (f359dd5) into main (c9d0529) will not change coverage.
The diff coverage is 100.00%.

❗ Current head f359dd5 differs from pull request most recent head 4d40673. Consider uploading reports for the commit 4d40673 to get more accurate results
Impacted file tree graph

@@            Coverage Diff            @@
##              main       #98   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines          180       163   -17     
=========================================
- Hits           180       163   -17     
Impacted Files Coverage Δ
xcdat/bounds.py 100.00% <100.00%> (ø)
xcdat/variable.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 c9d0529...4d40673. Read the comment docs.

- Add `.copy()` method to DataArrayBoundsAccessor

Add `copy_variable` function
Comment on lines +296 to +302
# A Dataset container to store the bounds from the parent Dataset.
# A Dataset is used instead of a dictionary so that it is interoperable
# with cf_xarray and the DatasetBoundsAccessor class. This allows for
# the dynamic generation of a bounds dict that is name-agnostic (e.g.,
# "lat", "latitude", "Y" for latitude bounds). Refer to the ``bounds``
# class property below for more information.
self._bounds = xr.Dataset()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added this comment for developers in case this confuses them on why a Dataset is being stored inside a DataArray accessor class (think of it as just a container, like a dict).

@tomvothecoder
Copy link
Collaborator Author

Hey @pochedls, I just finished my review. Let me know how things look, and I'll merge so we can move forward with #87/#95.

@pochedls
Copy link
Collaborator

@tomvothecoder - looks good to me! I noticed that within ts.bounds._bounds some of the axis arrays are repeated (e.g., lat is in this dataset in addition to lat_bnds even thought lat is already a part of the dataarray via ts.lat). I think I understand why this is and have no issue with this approach.

@tomvothecoder tomvothecoder merged commit 533d150 into main Aug 25, 2021
@tomvothecoder tomvothecoder deleted the bugfix/97-dim-bounds branch August 25, 2021 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected behavior with open_variable
2 participants