Skip to content

Commit

Permalink
Correct add_season to avoid duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
stella-bourdin committed Mar 28, 2022
1 parent bd1e821 commit 9d02eb4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dynamicopy/tc/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def storm_stats(tracks):
tracks.loc[tracks.ET.isna(), "ET"] = False
storms = (
tracks.groupby(["track_id"])[["hemisphere", "basin", "season", "month"]]
.agg(lambda x: x.value_counts().index[0]) #TODO : line responsible for the slow behavior
.agg(lambda x: x.value_counts().index[0]) #TODO : line responsible for the slow behavior / remplacer par pd.Series.mode : https://stackoverflow.com/questions/15222754/groupby-pandas-dataframe-and-select-most-common-value
.reset_index()
)
storms = storms.merge(
Expand Down
4 changes: 2 additions & 2 deletions dynamicopy/tc/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from ._basins import *
from shapely.geometry import Point

import pandas as pd

def add_season(tracks):
"""
Expand All @@ -23,7 +23,7 @@ def add_season(tracks):
.mean()
.astype(int)
.join(
tracks[["track_id", "hemisphere"]].drop_duplicates().set_index("track_id"),
tracks.groupby("track_id")[["hemisphere"]].agg(pd.Series.mode),
on="track_id",
)
)
Expand Down

0 comments on commit 9d02eb4

Please sign in to comment.