Skip to content

Commit

Permalink
Code review for #277
Browse files Browse the repository at this point in the history
  - Initialise dict with curly brackets
  - Improve exception handling in function 'to_pandas'
  - Improve error message in function 'to_ncCF'

Co-authored-by: Filipe <[email protected]>
  • Loading branch information
vinisalazar and ocefpaf committed Nov 16, 2022
1 parent c097922 commit b4d9d37
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions erddapy/core/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@
def to_pandas(url: str, requests_kwargs=None, **kw) -> pd.DataFrame:
"""Convert a URL to Pandas DataFrame."""
if requests_kwargs is None:
requests_kwargs = dict()
requests_kwargs = {}
data = urlopen(url, **requests_kwargs)
try:
return pd.read_csv(data, **kw)
except Exception as e:
print("Couldn't process response into Pandas DataFrame.")
print(f"{type(e)} occurred. Please see below for the traceback.")
raise
raise ValueError(f"Could not read url {url} with Pandas.read_csv.") from e


def to_ncCF(url: str, protocol: str = None, **kw) -> Dataset:
"""Convert a URL to a netCDF4 Dataset."""
if protocol == "griddap":
raise ValueError(
f"Cannot use ncCF with griddap. The URL you tried to access is: '{url}'.",
f"Cannot use .ncCF with griddap protocol. The URL you tried to access is: '{url}'.",
)
auth = kw.pop("auth", None)
return _nc_dataset(url, auth=auth, **kw)
Expand Down

0 comments on commit b4d9d37

Please sign in to comment.