Skip to content

Commit 483f751

Browse files
b8raoultmathause
andauthored
Disable the cfgrib backend if eccodes is not installed (#5083)
* Disable the cfgrib backend if eccodes is not installed If cfgrib is installed, but libeccodes.so is not installed on the system, Xarray does not load as cfgrib will throw a RuntimeError(), which is not caught. * Update xarray/backends/cfgrib_.py Co-authored-by: Mathias Hauser <[email protected]> * Update xarray/backends/cfgrib_.py Co-authored-by: Mathias Hauser <[email protected]> * Update cfgrib_.py Missing import * Run black * Update whats-new.rst * Update whats-new.rst * Update xarray/backends/cfgrib_.py Co-authored-by: Mathias Hauser <[email protected]>
1 parent 45b4436 commit 483f751

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

doc/whats-new.rst

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ New Features
6161
:py:class:`~core.groupby.DataArrayGroupBy`, inspired by pandas'
6262
:py:meth:`~pandas.core.groupby.GroupBy.get_group`.
6363
By `Deepak Cherian <https://github.com/dcherian>`_.
64+
- Disable the `cfgrib` backend if the `eccodes` library is not installed (:pull:`5083`). By `Baudouin Raoult <https://github.com/b8raoult>`_.
6465

6566
Breaking changes
6667
~~~~~~~~~~~~~~~~

xarray/backends/cfgrib_.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import warnings
23

34
import numpy as np
45

@@ -20,7 +21,12 @@
2021
has_cfgrib = True
2122
except ModuleNotFoundError:
2223
has_cfgrib = False
23-
24+
# cfgrib throws a RuntimeError if eccodes is not installed
25+
except RuntimeError:
26+
warnings.warn(
27+
"Failed to load cfgrib - most likely eccodes is missing. Try `import cfgrib` to get the error message"
28+
)
29+
has_cfgrib = False
2430

2531
# FIXME: Add a dedicated lock, even if ecCodes is supposed to be thread-safe
2632
# in most circumstances. See:

0 commit comments

Comments
 (0)