Uh oh!
There was an error while loading. Please reload this page.
Add tests for load_dataarray to increase code coverage - #1518
Conversation
| 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) |
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.
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.
…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.
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