Skip to content

Commit

Permalink
Merge pull request #297 from gulfofmaine/fix/erddap-sort
Browse files Browse the repository at this point in the history
Sort ERDDAP Dataframes by time before trying to select the latest value
  • Loading branch information
abkfenris authored Feb 12, 2021
2 parents e5fc235 + 678449b commit c417872
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Changes:

Fixes:

- Sort dataframes from ERDDAP by time before use. IOOS Sensor ERDDAP has a tendency to return data from latest to earliest, rather than from earliest to latest like all other ERDDAPs that I've tested against. [#287](https://github.com/gulfofmaine/buoy_barn/issues/287)

## 0.1.17 - 02/09/2020

Fixes:
Expand Down
12 changes: 11 additions & 1 deletion app/deployments/utils/erddap_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def setup_variables(


def retrieve_dataframe(server, dataset: str, constraints, timeseries) -> DataFrame:
""" Returns a dataframe from ERDDAP for a given dataset
Attempts to sort the dataframe by time """
e = setup_variables(
server.connection(),
dataset,
Expand All @@ -56,4 +59,11 @@ def retrieve_dataframe(server, dataset: str, constraints, timeseries) -> DataFra
os.environ.get("RETRIEVE_DATAFRAME_TIMEOUT_SECONDS", 60)
)

return e.to_pandas(parse_dates=True)
df = e.to_pandas(parse_dates=True)

try:
df = df.sort_values("time (UTC)")
except KeyError:
logger.warning(f"Unable to sort dataframe by `time (UTC)` for {dataset}")

return df

0 comments on commit c417872

Please sign in to comment.