Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use patrol_id as groupby in get_patrol_obs #340

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ecoscope/io/async_earthranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,7 @@ async def get_patrol_observations_with_patrol_filter(
relocations : ecoscope.base.Relocations
"""
observations = ecoscope.base.Relocations()
df_pt = None

if include_patrol_details:
df_pt = await self.get_patrol_types_dataframe()
df_pt = await self.get_patrol_types_dataframe() if include_patrol_details else None

tasks = []
async for patrol in self.get_patrols(since=since, until=until, patrol_type=patrol_type, status=status):
Expand All @@ -432,6 +429,9 @@ async def get_patrol_observations_with_patrol_filter(
observations = await asyncio.gather(*tasks)
observations = pd.concat(observations)

if include_patrol_details:
observations["groupby_col"] = observations["patrol_id"]

return observations

async def _get_observations_by_patrol(self, patrol, relocations=True, tz="UTC", patrol_types=None, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions ecoscope/io/earthranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ def get_patrol_observations(self, patrols_df, include_patrol_details=False, **kw
)
)
if len(observation) > 0:
observation["groupby_col"] = patrol["id"]
observations.append(observation)
except Exception as e:
print(
Expand Down
1 change: 1 addition & 0 deletions tests/test_asyncearthranger_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ async def test_get_patrol_observations_with_patrol_details(
assert not observations.empty
assert set(observations.columns) == set(get_patrol_observations_fields).union(get_patrol_details_fields)
assert type(observations["fixtime"] == pd.Timestamp)
pd.testing.assert_series_equal(observations["patrol_id"], observations["groupby_col"], check_names=False)


@pytest.mark.asyncio
Expand Down
1 change: 1 addition & 0 deletions tests/test_earthranger_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ def test_get_patrol_observations_with_patrol_details(er_io):
assert not observations.empty
assert "patrol_id" in observations.columns
assert "patrol_title" in observations.columns
pd.testing.assert_series_equal(observations["patrol_id"], observations["groupby_col"], check_names=False)


def test_users(er_io):
Expand Down