Skip to content

Commit

Permalink
Remove ** from kwargs to make them more explicit
Browse files Browse the repository at this point in the history
  - Code review for ioos#280
  • Loading branch information
vinisalazar committed Feb 22, 2023
1 parent b29a6d2 commit ace48ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
10 changes: 8 additions & 2 deletions erddapy/core/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@ def _urlopen(url: str, auth: Optional[tuple] = None, **kwargs: Dict) -> BinaryIO
return io.BytesIO(response.content)


def urlopen(url: str, auth: Optional[tuple] = None, **kwargs: Dict) -> BinaryIO:
def urlopen(
url: str,
auth: Optional[tuple] = None,
requests_kwargs: Optional[Dict] = None,
) -> BinaryIO:
"""Thin wrapper around httpx get content.
See httpx.get docs for the `params` and `kwargs` options.
"""
# Ignoring type checks here b/c mypy does not support decorated functions.
data = _urlopen(url=url, auth=auth, **kwargs) # type: ignore
if requests_kwargs is None:
requests_kwargs = {}
data = _urlopen(url=url, auth=auth, **requests_kwargs) # type: ignore
data.seek(0)
return data

Expand Down
16 changes: 11 additions & 5 deletions erddapy/erddapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,20 +331,26 @@ def get_download_url(
**kwargs,
)

def to_pandas(self, **kw):
def to_pandas(
self,
requests_kwargs: Optional[Dict] = None,
pandas_kwargs: Optional[Dict] = None,
):
"""Save a data request to a pandas.DataFrame.
Accepts any `pandas.read_csv` keyword arguments.
Accepts any `pandas.read_csv` keyword arguments, passed as a dictionary to pandas_kwargs.
This method uses the .csvp [1] response as the default for simplicity,
please check ERDDAP's documentation for the other csv options available.
[1] Download a ISO-8859-1 .csv file with line 1: name (units). Times are ISO 8601 strings.
"""
response = kw.pop("response", "csvp")
url = self.get_download_url(response=response, **kw)
return to_pandas(url, **kw)
if requests_kwargs is None:
requests_kwargs = {}
response = requests_kwargs.pop("response", "csvp")
url = self.get_download_url(response=response, **requests_kwargs)
return to_pandas(url, requests_kwargs, pandas_kwargs)

def to_ncCF(self, protocol: str = None, **kw):
"""Load the data request into a Climate and Forecast compliant netCDF4-python object."""
Expand Down

0 comments on commit ace48ac

Please sign in to comment.