diff --git a/erddapy/erddapy.py b/erddapy/erddapy.py index 8ba9d3d..edad55e 100644 --- a/erddapy/erddapy.py +++ b/erddapy/erddapy.py @@ -4,6 +4,7 @@ from typing import Dict, List, Optional, Tuple, Union import pandas as pd +import xarray as xr from erddapy.core.griddap import ( _griddap_check_constraints, @@ -367,7 +368,11 @@ def to_ncCF(self, protocol: str = None, **kw): url = self.get_download_url(response="ncCF", distinct=distinct) return to_ncCF(url, protocol=protocol, requests_kwargs=dict(**kw)) - def to_xarray(self, **kw): + def to_xarray( + self, + requests_kwargs: Optional[Dict] = None, + **kw, + ) -> "xr.Dataset": """Load the data request into a xarray.Dataset. Accepts any `xr.open_dataset` keyword arguments. @@ -380,7 +385,10 @@ def to_xarray(self, **kw): response = "ncCF" distinct = kw.pop("distinct", False) url = self.get_download_url(response=response, distinct=distinct) - requests_kwargs = {"auth": self.auth} + if requests_kwargs: + requests_kwargs = {"auth": self.auth} | requests_kwargs + else: + requests_kwargs = {"auth": self.auth} return to_xarray(url, response, requests_kwargs, xarray_kwargs=dict(**kw)) def to_iris(self, **kw):