Skip to content

Commit

Permalink
add request_kwargs to to_xarray
Browse files Browse the repository at this point in the history
  • Loading branch information
callumrollo committed Aug 8, 2023
1 parent d8bdf3f commit f8c7a8d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions erddapy/erddapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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):
Expand Down

0 comments on commit f8c7a8d

Please sign in to comment.