From 5df8a428d36a3909395777bc9bc36e2d56b7422c Mon Sep 17 00:00:00 2001 From: Ryan Abernathey Date: Sat, 13 Jul 2019 20:07:50 -0500 Subject: [PATCH] Allow other tutorial filename extensions (#3121) * switching out examples to use nbsphinx * added jupyter_client to doc env * allow non netcdf tutorial files --- xarray/tutorial.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/xarray/tutorial.py b/xarray/tutorial.py index 01d4f181d7f..8b4f8490d59 100644 --- a/xarray/tutorial.py +++ b/xarray/tutorial.py @@ -33,8 +33,9 @@ def open_dataset(name, cache=True, cache_dir=_default_cache_dir, Parameters ---------- name : str - Name of the netcdf file containing the dataset - ie. 'air_temperature' + Name of the file containing the dataset. If no suffix is given, assumed + to be netCDF ('.nc' is appended) + e.g. 'air_temperature' cache_dir : string, optional The directory in which to search for and write cached data. cache : boolean, optional @@ -51,10 +52,13 @@ def open_dataset(name, cache=True, cache_dir=_default_cache_dir, xarray.open_dataset """ + root, ext = _os.path.splitext(name) + if not ext: + ext = '.nc' + fullname = root + ext longdir = _os.path.expanduser(cache_dir) - fullname = name + '.nc' localfile = _os.sep.join((longdir, fullname)) - md5name = name + '.md5' + md5name = fullname + '.md5' md5file = _os.sep.join((longdir, md5name)) if not _os.path.exists(localfile):