Add tests for load_dataarray to increase code coverage#1518
Merged
Conversation
maxrjones
reviewed
Sep 17, 2021
Comment on lines
+11
to
+26
| def test_io_load_dataarray(): | ||
| """ | ||
| Check that load_dataarray works to read a NetCDF grid with | ||
| GMTDataArrayAccessor information loaded. | ||
| """ | ||
| with GMTTempFile(suffix=".nc") as tmpfile: | ||
| grid = xr.DataArray( | ||
| data=np.random.rand(2, 2), coords=[[0.1, 0.2], [0.3, 0.4]], dims=("x", "y") | ||
| ) | ||
| grid.to_netcdf(tmpfile.name) | ||
| dataarray = load_dataarray(tmpfile.name) | ||
| assert dataarray.gmt.gtype == 0 # Cartesian grid | ||
| assert dataarray.gmt.registration == 1 # Pixel registration | ||
| # this would fail if we used xr.open_dataarray instead of | ||
| # load_dataarray | ||
| dataarray.to_netcdf(tmpfile.name) |
Member
There was a problem hiding this comment.
Can you clarify why we need this test? To me, it seems redundant with the other tests that read NetCDF grids with GMTDataArrayAccessor information loaded with the exception of the to_netcdf line, but that is xarray functionality rather than pygmt.
Member
Author
There was a problem hiding this comment.
This test was based on xarray's similar test at https://github.com/pydata/xarray/blob/befd1b98bd84047d62307419a30bcda7a0727926/xarray/tests/test_backends.py#L3729-L3736. I agree that this doesn't increase test coverage and seems redundant, but I feel like we should still have an explicit unit test for load_dataarray here, rather than just testing it indirectly in other functions.
maxrjones
approved these changes
Sep 17, 2021
seisman
approved these changes
Sep 18, 2021
michaelgrund
approved these changes
Sep 18, 2021
sixy6e
pushed a commit
to sixy6e/pygmt
that referenced
this pull request
Dec 21, 2022
…gTools#1518) Patches missing code coverage of pygmt.load_dataarray function wrapped in GenericMappingTools#1439. Checks that a NetCDF grid can be read with GMTDataArrayAccessor information loaded, and that load_dataarray fails when the cache argument is used.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of proposed changes
Patches missing code coverage of
pygmt.load_dataarrayfunction wrapped in #1439. This commit was cherry-picked from test_io_load_dataarray in #1494.Fixes #
Reminders
make formatandmake checkto make sure the code follows the style guide.doc/api/index.rst.Slash Commands
You can write slash commands (
/command) in the first line of a comment to performspecific operations. Supported slash commands are:
/format: automatically format and lint the code/test-gmt-dev: run full tests on the latest GMT development version