diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 3c53d3bfb04..3c091aa8900 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -34,6 +34,8 @@ Bug fixes allowing the ``encoding`` and ``unlimited_dims`` options with ``save_mfdataset``. (:issue:`6684`) By `Travis A. O'Brien `_. +- Fix backend support of pydap versions <3.3.0 (:issue:`6648`, :pull:`6656`). + By `Hauke Schulz `_. - :py:meth:`Dataset.where` with ``drop=True`` now behaves correctly with mixed dimensions. (:issue:`6227`, :pull:`6690`) By `Michael Niklas `_. diff --git a/xarray/backends/pydap_.py b/xarray/backends/pydap_.py index 60e3d047b61..a6ac36104fd 100644 --- a/xarray/backends/pydap_.py +++ b/xarray/backends/pydap_.py @@ -1,6 +1,7 @@ from __future__ import annotations import numpy as np +from packaging.version import Version from ..core import indexing from ..core.pycompat import integer_types @@ -17,7 +18,9 @@ try: import pydap.client + import pydap.lib + pydap_version = pydap.lib.__version__ has_pydap = True except ModuleNotFoundError: has_pydap = False @@ -99,29 +102,24 @@ def open( user_charset=None, ): - if output_grid is None: - output_grid = True - - if verify is None: - verify = True - if timeout is None: from pydap.lib import DEFAULT_TIMEOUT timeout = DEFAULT_TIMEOUT - if user_charset is None: - user_charset = "ascii" - - ds = pydap.client.open_url( - url=url, - application=application, - session=session, - output_grid=output_grid, - timeout=timeout, - verify=verify, - user_charset=user_charset, - ) + kwargs = { + "url": url, + "application": application, + "session": session, + "output_grid": output_grid or True, + "timeout": timeout, + } + if Version(pydap_version) >= Version("3.3.0"): + if verify is not None: + kwargs.update({"verify": verify}) + if user_charset is not None: + kwargs.update({"user_charset": user_charset}) + ds = pydap.client.open_url(**kwargs) return cls(ds) def open_store_variable(self, var):