Skip to content

Commit

Permalink
Standardise style of kwargs
Browse files Browse the repository at this point in the history
  - Use Optional[Dict] for all third-party libraries kwargs
  - Code review for ioos#280

  Co-authored-by: Filipe <ocefpaf@gmail.com>
  Co-authored-by: Alex Kerney <abk@mac.com>
  • Loading branch information
vinisalazar committed Nov 29, 2022
1 parent e829626 commit d7ca233
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions erddapy/core/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@


def to_pandas(
url: str, requests_kwargs: Optional[Dict] = None, **pandas_kwargs
url: str,
requests_kwargs: Optional[Dict] = None,
pandas_kwargs: Optional[Dict] = None,
) -> pd.DataFrame:
"""
Convert a URL to Pandas DataFrame.
Expand All @@ -28,6 +30,8 @@ def to_pandas(
"""
if requests_kwargs is None:
requests_kwargs = {}
if pandas_kwargs is None:
pandas_kwargs = {}
data = urlopen(url, **requests_kwargs)
try:
return pd.read_csv(data, **pandas_kwargs)
Expand Down Expand Up @@ -60,26 +64,32 @@ def to_xarray(
url: str,
response="opendap",
requests_kwargs: Optional[Dict] = None,
**xarray_kwargs,
xarray_kwargs: Optional[Dict] = None,
) -> xr.Dataset:
"""
Convert a URL to an xarray dataset.
url: URL to request data from.
response: type of response to be requested from the server.
requests_kwargs: arguments to be passed to urlopen method
requests_kwargs: arguments to be passed to urlopen method.
xarray_kwargs: kwargs to be passed to third-party library (xarray).
"""
if requests_kwargs is None:
requests_kwargs = {}
if xarray_kwargs is None:
xarray_kwargs = {}
if response == "opendap":
return xr.open_dataset(url, **xarray_kwargs)
else:
nc = _nc_dataset(url, **requests_kwargs)
return xr.open_dataset(xr.backends.NetCDF4DataStore(nc), **xarray_kwargs)


def to_iris(url: str, requests_kwargs: Optional[Dict] = None, **iris_kwargs):
def to_iris(
url: str,
requests_kwargs: Optional[Dict] = None,
iris_kwargs: Optional[Dict] = None,
):
"""
Convert a URL to an iris CubeList.
Expand All @@ -89,6 +99,8 @@ def to_iris(url: str, requests_kwargs: Optional[Dict] = None, **iris_kwargs):
"""
if requests_kwargs is None:
requests_kwargs = {}
if iris_kwargs is None:
iris_kwargs = {}
data = urlopen(url, **requests_kwargs)
with _tempnc(data) as tmp:
cubes = iris.load_raw(tmp, **iris_kwargs)
Expand Down

0 comments on commit d7ca233

Please sign in to comment.