-
Notifications
You must be signed in to change notification settings - Fork 224
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good
…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_dataarray
function wrapped in #1439. This commit was cherry-picked from test_io_load_dataarray in #1494.Fixes #
Reminders
make format
andmake check
to 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