Skip to content

Commit 1b5d24f

Browse files
More informative error message for error reading InferenceData from NetCDF (#1637)
* More informative error message. * Blacken and pylint. * Update Changelog for PR 1637. Co-authored-by: Oriol Abril-Pla <[email protected]>
1 parent 99764f6 commit 1b5d24f

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Improved retrieving or pointwise log likelihood in `from_cmdstanpy`, `from_cmdstan` and `from_pystan` ([1579](https://github.com/arviz-devs/arviz/pull/1579) and [1599](https://github.com/arviz-devs/arviz/pull/1599))
1010
* Added interactive legend to bokeh `forestplot` ([1591](https://github.com/arviz-devs/arviz/pull/1591))
1111
* Added interactive legend to bokeh `ppcplot` ([1602](https://github.com/arviz-devs/arviz/pull/1602))
12+
* Add more helpful error message for HDF5 problems reading `InferenceData` from NetCDF ([1637](https://github.com/arviz-devs/arviz/pull/1637))
1213
* Added `data.log_likelihood`, `stats.ic_compare_method` and `plot.density_kind` to `rcParams` ([1611](https://github.com/arviz-devs/arviz/pull/1611))
1314
* Improve error messages in `stats.compare()`, and `var_name` parameter. ([1616](https://github.com/arviz-devs/arviz/pull/1616))
1415

arviz/data/inference_data.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -328,16 +328,30 @@ def from_netcdf(filename: str) -> "InferenceData":
328328
InferenceData object
329329
"""
330330
groups = {}
331-
with nc.Dataset(filename, mode="r") as data:
332-
data_groups = list(data.groups)
331+
try:
332+
with nc.Dataset(filename, mode="r") as data:
333+
data_groups = list(data.groups)
333334

334-
for group in data_groups:
335-
with xr.open_dataset(filename, group=group) as data:
336-
if rcParams["data.load"] == "eager":
337-
groups[group] = data.load()
338-
else:
339-
groups[group] = data
340-
return InferenceData(**groups)
335+
for group in data_groups:
336+
with xr.open_dataset(filename, group=group) as data:
337+
if rcParams["data.load"] == "eager":
338+
groups[group] = data.load()
339+
else:
340+
groups[group] = data
341+
return InferenceData(**groups)
342+
except OSError as e: # pylint: disable=invalid-name
343+
if e.errno == -101:
344+
raise type(e)(
345+
str(e)
346+
+ (
347+
" while reading a NetCDF file. This is probably an error in HDF5, "
348+
"which happens because your OS does not support HDF5 file locking. See "
349+
"https://stackoverflow.com/questions/49317927/"
350+
"errno-101-netcdf-hdf-error-when-opening-netcdf-file#49317928"
351+
" for a possible solution."
352+
)
353+
)
354+
raise e
341355

342356
def to_netcdf(
343357
self, filename: str, compress: bool = True, groups: Optional[List[str]] = None

0 commit comments

Comments
 (0)