Skip to content

Commit

Permalink
Only load GMTDataArray accessor info when engine!=rasterio
Browse files Browse the repository at this point in the history
Prevent segfault when loading accessor info from an xarray.Datarray loaded using rioxarray.open_rasterio.
  • Loading branch information
weiji14 committed Feb 18, 2024
1 parent cd4cab6 commit fc060ea
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pygmt/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ def load_dataarray(filename_or_obj, **kwargs):
if kwargs.get("engine") == "rasterio":
import rioxarray

Check warning on line 43 in pygmt/io.py

View check run for this annotation

Codecov / codecov/patch

pygmt/io.py#L43

Added line #L43 was not covered by tests

open_dataarray_func = rioxarray.open_rasterio
kwargs.pop("engine")
with rioxarray.open_rasterio(filename_or_obj, **kwargs) as dataarray:
result = dataarray.load()

Check warning on line 47 in pygmt/io.py

View check run for this annotation

Codecov / codecov/patch

pygmt/io.py#L45-L47

Added lines #L45 - L47 were not covered by tests
else:
open_dataarray_func = xr.open_dataarray

with open_dataarray_func(filename_or_obj, **kwargs) as dataarray:
result = dataarray.load()
_ = result.gmt # load GMTDataArray accessor information
with xr.open_dataarray(filename_or_obj, **kwargs) as dataarray:
result = dataarray.load()
_ = result.gmt # load GMTDataArray accessor information

return result

0 comments on commit fc060ea

Please sign in to comment.