From 5e9a70636b29c55c25603b86a69f697a490e60bf Mon Sep 17 00:00:00 2001 From: biwano Date: Tue, 10 Oct 2023 16:40:37 +0200 Subject: [PATCH] Explicitly do not include group keys --- src/apps/services/cache.py | 8 ++++---- src/apps/services/credits.py | 10 +++++----- src/apps/services/retirements.py | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/apps/services/cache.py b/src/apps/services/cache.py index a70e5d6..97eeb39 100644 --- a/src/apps/services/cache.py +++ b/src/apps/services/cache.py @@ -188,7 +188,7 @@ def daily_agg(self, df, columns): date_column = columns[0] """Adds an aggregation by day""" df = self.date_manipulations(df, date_column, "daily") - df = df.groupby(columns) + df = df.groupby(columns, group_keys=False) return df def monthly_agg(self, df, columns): @@ -197,7 +197,7 @@ def monthly_agg(self, df, columns): columns = [columns] date_column = columns[0] df = self.date_manipulations(df, date_column, "monthly") - df = df.groupby(columns) + df = df.groupby(columns, group_keys=False) return df @final_cached_command() @@ -226,7 +226,7 @@ def sum(self, df, column): def sum_over_time(self, df, date_column, column, freq): df = self.date_manipulations(df, date_column, freq) df = df.sort_values(by=date_column, ascending=True) - df = df.groupby(date_column)[column].sum().to_frame().reset_index() + df = df.groupby(date_column, group_keys=False)[column].sum().to_frame().reset_index() df[column] = df[column].cumsum() return df @@ -238,7 +238,7 @@ def cumsum(self, df, column): @chained_cached_command() def monthly_sample(self, df, date_column): """Samples daily data into monthly data""" - return df.groupby(pd.DatetimeIndex(df[date_column]).to_period('M')).nth(-1).reset_index(drop=True) + return df.groupby(pd.DatetimeIndex(df[date_column]).to_period('M'), group_keys=False).nth(-1).reset_index(drop=True) def date_manipulations(self, df, date_column, freq): if date_column not in df: diff --git a/src/apps/services/credits.py b/src/apps/services/credits.py index 07d0463..5231208 100644 --- a/src/apps/services/credits.py +++ b/src/apps/services/credits.py @@ -92,22 +92,22 @@ def filter(self, df, bridge, pool, status): @chained_cached_command() def vintage_agg(self, df): """Adds an aggregation on vintage""" - df = df.groupby("vintage") + df = df.groupby("vintage", group_keys=False) return df @chained_cached_command() def countries_agg(self, df): - df = df.groupby(["country", "country_code"]) + df = df.groupby(["country", "country_code"], group_keys=False) return df @chained_cached_command() def projects_agg(self, df): - df = df.groupby("project_type") + df = df.groupby("project_type", group_keys=False) return df @chained_cached_command() def methodologies_agg(self, df): - df = df.groupby("methodology") + df = df.groupby("methodology", group_keys=False) return df @@ -123,7 +123,7 @@ def pool_summary(self, df, kept_fields=[]): "mco2_quantity" ] if isinstance(df, pd.DataFrame): - df = df.groupby(lambda x: True) + df = df.groupby(lambda x: True, group_keys=False) if not isinstance(kept_fields, list): kept_fields = [kept_fields] diff --git a/src/apps/services/retirements.py b/src/apps/services/retirements.py index 5f36c41..d70229d 100644 --- a/src/apps/services/retirements.py +++ b/src/apps/services/retirements.py @@ -77,10 +77,10 @@ def summary(df): @chained_cached_command() def beneficiaries_agg(self, df): - df = df.groupby("beneficiary") + df = df.groupby("beneficiary", group_keys=False) return df @chained_cached_command() def tokens_agg(self, df): - df = df.groupby("token") + df = df.groupby("token", group_keys=False) return df