Skip to content

Commit 0159e45

Browse files
authored
Delete built-in cfgrib backend (#7670)
* Delete built-in cfgrib backend * More deletes * readd cfgrib to mypy ignores * Fix docstring
1 parent c5b88bf commit 0159e45

20 files changed

+20
-236
lines changed

ci/requirements/all-but-dask.yml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ dependencies:
1010
- bottleneck
1111
- cartopy
1212
- cdms2
13-
- cfgrib
1413
- cftime
1514
- coveralls
1615
- flox

ci/requirements/doc.yml

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ dependencies:
77
- python=3.10
88
- bottleneck
99
- cartopy
10-
- cfgrib>=0.9
1110
- dask-core>=2022.1
1211
- h5netcdf>=0.13
1312
- ipykernel

ci/requirements/environment-py311.yml

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ dependencies:
88
- bottleneck
99
- cartopy
1010
# - cdms2
11-
- cfgrib
1211
- cftime
1312
- dask-core
1413
- distributed

ci/requirements/environment-windows-py311.yml

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ dependencies:
66
- bottleneck
77
- cartopy
88
# - cdms2 # Not available on Windows
9-
# - cfgrib # Causes Python interpreter crash on Windows: https://github.com/pydata/xarray/pull/3340
109
- cftime
1110
- dask-core
1211
- distributed

ci/requirements/environment-windows.yml

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ dependencies:
66
- bottleneck
77
- cartopy
88
# - cdms2 # Not available on Windows
9-
# - cfgrib # Causes Python interpreter crash on Windows: https://github.com/pydata/xarray/pull/3340
109
- cftime
1110
- dask-core
1211
- distributed

ci/requirements/environment.yml

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ dependencies:
88
- bottleneck
99
- cartopy
1010
- cdms2
11-
- cfgrib
1211
- cftime
1312
- dask-core
1413
- distributed

ci/requirements/min-all-deps.yml

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ dependencies:
1212
- bottleneck=1.3
1313
- cartopy=0.20
1414
- cdms2=3.1
15-
- cfgrib=0.9
1615
- cftime=1.5
1716
- coveralls
1817
- dask-core=2022.1

doc/getting-started-guide/installing.rst

-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ For netCDF and IO
4545
other gridded raster datasets.
4646
- `iris <https://github.com/scitools/iris>`__: for conversion to and from iris'
4747
Cube objects
48-
- `cfgrib <https://github.com/ecmwf/cfgrib>`__: for reading GRIB files via the
49-
*ECMWF ecCodes* library.
5048

5149
For accelerating xarray
5250
~~~~~~~~~~~~~~~~~~~~~~~

doc/user-guide/io.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ GRIB format via cfgrib
12571257

12581258
Xarray supports reading GRIB files via ECMWF cfgrib_ python driver,
12591259
if it is installed. To open a GRIB file supply ``engine='cfgrib'``
1260-
to :py:func:`open_dataset`:
1260+
to :py:func:`open_dataset` after installing cfgrib_:
12611261

12621262
.. ipython::
12631263
:verbatim:

doc/whats-new.rst

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ Documentation
5151
Internal Changes
5252
~~~~~~~~~~~~~~~~
5353

54+
- Remove internal support for reading GRIB files through the ``cfgrib`` backend. ``cfgrib`` now uses the external
55+
backend interface, so no existing code should break.
56+
By `Deepak Cherian <https://github.com/dcherian>`_.
57+
5458
.. _whats-new.2023.03.0:
5559

5660
v2023.03.0 (March 22, 2023)

setup.cfg

-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ io =
8989
fsspec
9090
cftime
9191
rasterio
92-
cfgrib
9392
pooch
9493
## Scitools packages & dependencies (e.g: cartopy, cf-units) can be hard to install
9594
# scitools-iris

xarray/backends/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
DataStores provide a uniform interface for saving and loading data in different
44
formats. They should not be used directly, but rather through Dataset objects.
55
"""
6-
from xarray.backends.cfgrib_ import CfGribDataStore
76
from xarray.backends.common import AbstractDataStore, BackendArray, BackendEntrypoint
87
from xarray.backends.file_manager import (
98
CachingFileManager,
@@ -30,7 +29,6 @@
3029
"BackendEntrypoint",
3130
"FileManager",
3231
"CachingFileManager",
33-
"CfGribDataStore",
3432
"DummyFileManager",
3533
"InMemoryDataStore",
3634
"NetCDF4DataStore",

xarray/backends/api.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
T_NetcdfEngine = Literal["netcdf4", "scipy", "h5netcdf"]
4444
T_Engine = Union[
4545
T_NetcdfEngine,
46-
Literal["pydap", "pynio", "pseudonetcdf", "cfgrib", "zarr"],
46+
Literal["pydap", "pynio", "pseudonetcdf", "zarr"],
4747
type[BackendEntrypoint],
4848
str, # no nice typing support for custom backends
4949
None,
@@ -64,7 +64,6 @@
6464
"h5netcdf": backends.H5NetCDFStore.open,
6565
"pynio": backends.NioDataStore,
6666
"pseudonetcdf": backends.PseudoNetCDFDataStore.open,
67-
"cfgrib": backends.CfGribDataStore,
6867
"zarr": backends.ZarrStore.open_group,
6968
}
7069

@@ -387,7 +386,7 @@ def open_dataset(
387386
ends with .gz, in which case the file is gunzipped and opened with
388387
scipy.io.netcdf (only netCDF3 supported). Byte-strings or file-like
389388
objects are opened by scipy.io.netcdf (netCDF3) or h5py (netCDF4/HDF).
390-
engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio", "cfgrib", \
389+
engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio", \
391390
"pseudonetcdf", "zarr", None}, installed backend \
392391
or subclass of xarray.backends.BackendEntrypoint, optional
393392
Engine to use when reading files. If not provided, the default engine
@@ -479,7 +478,7 @@ def open_dataset(
479478
relevant when using dask or another form of parallelism. By default,
480479
appropriate locks are chosen to safely read and write files with the
481480
currently active dask scheduler. Supported by "netcdf4", "h5netcdf",
482-
"scipy", "pynio", "pseudonetcdf", "cfgrib".
481+
"scipy", "pynio", "pseudonetcdf".
483482
484483
See engine open function for kwargs accepted by each specific engine.
485484
@@ -576,7 +575,7 @@ def open_dataarray(
576575
ends with .gz, in which case the file is gunzipped and opened with
577576
scipy.io.netcdf (only netCDF3 supported). Byte-strings or file-like
578577
objects are opened by scipy.io.netcdf (netCDF3) or h5py (netCDF4/HDF).
579-
engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio", "cfgrib", \
578+
engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio", \
580579
"pseudonetcdf", "zarr", None}, installed backend \
581580
or subclass of xarray.backends.BackendEntrypoint, optional
582581
Engine to use when reading files. If not provided, the default engine
@@ -666,7 +665,7 @@ def open_dataarray(
666665
relevant when using dask or another form of parallelism. By default,
667666
appropriate locks are chosen to safely read and write files with the
668667
currently active dask scheduler. Supported by "netcdf4", "h5netcdf",
669-
"scipy", "pynio", "pseudonetcdf", "cfgrib".
668+
"scipy", "pynio", "pseudonetcdf".
670669
671670
See engine open function for kwargs accepted by each specific engine.
672671
@@ -803,7 +802,7 @@ def open_mfdataset(
803802
If provided, call this function on each dataset prior to concatenation.
804803
You can find the file-name from which each dataset was loaded in
805804
``ds.encoding["source"]``.
806-
engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio", "cfgrib", \
805+
engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio", \
807806
"pseudonetcdf", "zarr", None}, installed backend \
808807
or subclass of xarray.backends.BackendEntrypoint, optional
809808
Engine to use when reading files. If not provided, the default engine

xarray/backends/cfgrib_.py

-148
This file was deleted.

xarray/tests/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def _importorskip(
7575
has_zarr, requires_zarr = _importorskip("zarr")
7676
has_fsspec, requires_fsspec = _importorskip("fsspec")
7777
has_iris, requires_iris = _importorskip("iris")
78-
has_cfgrib, requires_cfgrib = _importorskip("cfgrib")
7978
has_numbagg, requires_numbagg = _importorskip("numbagg")
8079
has_seaborn, requires_seaborn = _importorskip("seaborn")
8180
has_sparse, requires_sparse = _importorskip("sparse")

xarray/tests/test_backends.py

-46
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
has_scipy,
6464
mock,
6565
network,
66-
requires_cfgrib,
6766
requires_cftime,
6867
requires_dask,
6968
requires_fsspec,
@@ -4186,51 +4185,6 @@ def test_weakrefs(self) -> None:
41864185
assert_identical(actual, expected)
41874186

41884187

4189-
@requires_cfgrib
4190-
class TestCfGrib:
4191-
def test_read(self) -> None:
4192-
expected = {
4193-
"number": 2,
4194-
"time": 3,
4195-
"isobaricInhPa": 2,
4196-
"latitude": 3,
4197-
"longitude": 4,
4198-
}
4199-
with open_example_dataset("example.grib", engine="cfgrib") as ds:
4200-
assert ds.dims == expected
4201-
assert list(ds.data_vars) == ["z", "t"]
4202-
assert ds["z"].min() == 12660.0
4203-
4204-
def test_read_filter_by_keys(self) -> None:
4205-
kwargs = {"filter_by_keys": {"shortName": "t"}}
4206-
expected = {
4207-
"number": 2,
4208-
"time": 3,
4209-
"isobaricInhPa": 2,
4210-
"latitude": 3,
4211-
"longitude": 4,
4212-
}
4213-
with open_example_dataset(
4214-
"example.grib", engine="cfgrib", backend_kwargs=kwargs
4215-
) as ds:
4216-
assert ds.dims == expected
4217-
assert list(ds.data_vars) == ["t"]
4218-
assert ds["t"].min() == 231.0
4219-
4220-
def test_read_outer(self) -> None:
4221-
expected = {
4222-
"number": 2,
4223-
"time": 3,
4224-
"isobaricInhPa": 2,
4225-
"latitude": 2,
4226-
"longitude": 3,
4227-
}
4228-
with open_example_dataset("example.grib", engine="cfgrib") as ds:
4229-
res = ds.isel(latitude=[0, 2], longitude=[0, 1, 2])
4230-
assert res.dims == expected
4231-
assert res["t"].min() == 231.0
4232-
4233-
42344188
@requires_pseudonetcdf
42354189
@pytest.mark.filterwarnings("ignore:IOAPI_ISPH is assumed to be 6370000")
42364190
class TestPseudoNetCDFFormat:

0 commit comments

Comments
 (0)