diff --git a/ecoscope/io/earthranger.py b/ecoscope/io/earthranger.py index 8b8f20d..4149e32 100644 --- a/ecoscope/io/earthranger.py +++ b/ecoscope/io/earthranger.py @@ -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") diff --git a/tests/test_earthranger_io.py b/tests/test_earthranger_io.py index 5224d4a..13cb1fc 100644 --- a/tests/test_earthranger_io.py +++ b/tests/test_earthranger_io.py @@ -1,5 +1,6 @@ import datetime import uuid +from unittest.mock import patch import geopandas as gpd import pandas as pd @@ -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( [