Skip to content

Commit

Permalink
support printing Datasets on xarray>2024.1.0 (#153)
Browse files Browse the repository at this point in the history
* fix dtype to work with xarray > 202401

* move print dataset test to new file

* fixed test that wasn't working if xarray<2024.2.0

* simplify print test

* just need to see of repr(ds1) works, not test the results
  • Loading branch information
TimothyCera-NOAA authored Jul 1, 2024
1 parent cd3c7f5 commit f499a05
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/grib2io/xarray_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from dataclasses import dataclass, field, astuple
import itertools
import logging
from pathlib import Path
import typing

import numpy as np
Expand Down Expand Up @@ -100,7 +99,7 @@ class GribBackendArray(BackendArray):
def __init__(self, array, lock):
self.array = array
self.shape = array.shape
self.dtype = array.dtype
self.dtype = np.dtype(array.dtype)
self.lock = lock


Expand Down
22 changes: 22 additions & 0 deletions tests/test_print_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import xarray as xr


def test_da_repr(tmp_path, request):
"""Test writing a single DataArray to a single grib2 message."""
target_dir = tmp_path / "test_to_grib2"
target_dir.mkdir()

datadir = request.config.rootdir / "tests" / "data" / "gfs_20221107"

filters = {
"productDefinitionTemplateNumber": 0,
"typeOfFirstFixedSurface": 1,
"shortName": "TMP",
}
ds1 = xr.open_dataset(
datadir / "gfs.t00z.pgrb2.1p00.f012_subset",
engine="grib2io",
filters=filters,
)

_ = repr(ds1)

0 comments on commit f499a05

Please sign in to comment.