Skip to content

Commit

Permalink
Return empty DF when no data in get_patrol_evnts (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
atmorling authored Nov 18, 2024
1 parent f937fd1 commit e0fcd3a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ecoscope/io/earthranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,10 @@ def get_patrol_events(
event["patrol_segment_id"] = segment.get("id")
events.append(event)
events_df = pd.DataFrame(events)
events_df = clean_time_cols(events_df)
if events_df.empty:
return events_df

events_df = clean_time_cols(events_df)
events_df["geometry"] = events_df["geojson"].apply(lambda x: shape(x.get("geometry")))
events_df["time"] = events_df["geojson"].apply(
lambda x: datetime.datetime.strptime(x.get("properties").get("datetime"), "%Y-%m-%dT%H:%M:%S%z")
Expand Down
12 changes: 12 additions & 0 deletions tests/test_earthranger_io.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import uuid
from unittest.mock import patch

import geopandas as gpd
import pandas as pd
Expand Down Expand Up @@ -154,6 +155,17 @@ def test_get_patrol_events(er_io):
assert "time" in events


@patch("ecoscope.io.EarthRangerIO.get_patrols")
def test_get_patrol_events_empty(patrols_mock, er_io):
patrols_mock.return_value = pd.DataFrame()

events = er_io.get_patrol_events(
since=pd.Timestamp("2017-01-01").isoformat(),
until=pd.Timestamp("2017-04-01").isoformat(),
)
assert events.empty


def test_post_observations(er_io):
observations = gpd.GeoDataFrame.from_dict(
[
Expand Down

0 comments on commit e0fcd3a

Please sign in to comment.