Skip to content

Commit

Permalink
Explicitly do not include group keys
Browse files Browse the repository at this point in the history
  • Loading branch information
biwano committed Oct 10, 2023
1 parent fecc3bc commit 5e9a706
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/apps/services/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions src/apps/services/credits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions src/apps/services/retirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5e9a706

Please sign in to comment.