Skip to content

Commit 63b2994

Browse files
author
benoit-cty
committed
Fix pandas warning
1 parent 2faf374 commit 63b2994

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

codecarbon/output_methods/file.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,26 @@ def out(self, total: EmissionsData, delta: EmissionsData):
4646
logger.info("Backing up old emission file")
4747
backup(self.save_file_path)
4848
file_exists = False
49-
49+
new_df = pd.DataFrame.from_records([dict(total.values)])
50+
new_df = new_df.dropna(axis=1, how="all")
5051
if not file_exists:
5152
df = pd.DataFrame(columns=total.values.keys())
52-
df = pd.concat([df, pd.DataFrame.from_records([dict(total.values)])])
53+
df = pd.concat([df, new_df])
5354
elif self.on_csv_write == "append":
5455
df = pd.read_csv(self.save_file_path)
55-
df = pd.concat([df, pd.DataFrame.from_records([dict(total.values)])])
56+
df = pd.concat([df, new_df])
5657
else:
5758
df = pd.read_csv(self.save_file_path)
5859
df_run = df.loc[df.run_id == total.run_id]
5960
if len(df_run) < 1:
60-
df = pd.concat([df, pd.DataFrame.from_records([dict(total.values)])])
61+
df = pd.concat([df, new_df])
6162
elif len(df_run) > 1:
6263
logger.warning(
6364
f"CSV contains more than 1 ({len(df_run)})"
6465
+ f" rows with current run ID ({total.run_id})."
6566
+ "Appending instead of updating."
6667
)
67-
df = pd.concat([df, pd.DataFrame.from_records([dict(total.values)])])
68+
df = pd.concat([df, new_df])
6869
else:
6970
df.at[df.run_id == total.run_id, total.values.keys()] = (
7071
total.values.values()

0 commit comments

Comments
 (0)