From e3c858921501db6743fa3488a8e2053bf9567f39 Mon Sep 17 00:00:00 2001 From: Jonathan Joyce Date: Thu, 31 Jan 2019 15:44:48 -0700 Subject: [PATCH 1/3] BUG: Pass kwargs to the FileManager for pynio engine (#2380) --- doc/whats-new.rst | 3 +++ xarray/backends/pynio_.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index b7ca384ff09..be57d15e586 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -70,6 +70,9 @@ Bug fixes :py:class:`CFTimeIndex` now results in a :py:class:`pandas.TimedeltaIndex` instead of raising a ``TypeError`` (:issue:`2671`). By `Spencer Clark `_. +- backend_kwargs are no longer ignored when using open_dataset with pynio engine + (:issue:'2380') + By 'Jonathan Joyce '_. .. _whats-new.0.11.3: diff --git a/xarray/backends/pynio_.py b/xarray/backends/pynio_.py index 0995a39019d..f8033551f96 100644 --- a/xarray/backends/pynio_.py +++ b/xarray/backends/pynio_.py @@ -45,13 +45,13 @@ class NioDataStore(AbstractDataStore): """Store for accessing datasets via PyNIO """ - def __init__(self, filename, mode='r', lock=None): + def __init__(self, filename, mode='r', lock=None, **kwargs): import Nio if lock is None: lock = PYNIO_LOCK self.lock = ensure_lock(lock) self._manager = CachingFileManager( - Nio.open_file, filename, lock=lock, mode=mode) + Nio.open_file, filename, lock=lock, mode=mode, kwargs=kwargs) # xarray provides its own support for FillValue, # so turn off PyNIO's support for the same. self.ds.set_option('MaskedArrayMode', 'MaskedNever') From c456e918dfe7c885927b75d58c41e8171dcf0445 Mon Sep 17 00:00:00 2001 From: Jonathan Joyce Date: Mon, 4 Feb 2019 17:34:46 -0700 Subject: [PATCH 2/3] TST: Added test for pynio kwargs passing (#2380) --- xarray/tests/test_backends.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 55e4eb7c8db..5e1fc646c86 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -2547,6 +2547,12 @@ def test_write_store(self): def open(self, path, **kwargs): with open_dataset(path, engine='pynio', **kwargs) as ds: yield ds + + def test_kwargs(self): + kwargs={'format':'grib'} + path = os.path.join(os.path.dirname(__file__), 'data', 'example') + with backends.NioDataStore(path, **kwargs) as store: + assert store._manager._kwargs['format'] == 'grib' def save(self, dataset, path, **kwargs): return dataset.to_netcdf(path, engine='scipy', **kwargs) From 97e8b404c8c84f68fa56f71131cc71a1921a4428 Mon Sep 17 00:00:00 2001 From: Jonathan Joyce Date: Mon, 4 Feb 2019 17:45:30 -0700 Subject: [PATCH 3/3] Fixed formatting (#2380) --- xarray/tests/test_backends.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 5e1fc646c86..c8b759ba18a 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -2547,12 +2547,12 @@ def test_write_store(self): def open(self, path, **kwargs): with open_dataset(path, engine='pynio', **kwargs) as ds: yield ds - + def test_kwargs(self): - kwargs={'format':'grib'} + kwargs = {'format': 'grib'} path = os.path.join(os.path.dirname(__file__), 'data', 'example') - with backends.NioDataStore(path, **kwargs) as store: - assert store._manager._kwargs['format'] == 'grib' + with backends.NioDataStore(path, **kwargs) as store: + assert store._manager._kwargs['format'] == 'grib' def save(self, dataset, path, **kwargs): return dataset.to_netcdf(path, engine='scipy', **kwargs)