Skip to content

Commit

Permalink
Merge pull request #669 from VijayKalmath/Fix-PandasDeprecatedWarning
Browse files Browse the repository at this point in the history
Fix FutureWarning caused by pandas append method
  • Loading branch information
jxmorris12 committed Jun 18, 2022
2 parents 54c3141 + 906ab0b commit 6978804
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions textattack/loggers/csv_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, filename="results.csv", color_method="file"):
logger.info(f"Logging to CSV at path {filename}")
self.filename = filename
self.color_method = color_method
self.df = pd.DataFrame()
self.row_list = []
self._flushed = True

def log_attack_result(self, result):
Expand All @@ -38,10 +38,11 @@ def log_attack_result(self, result):
"num_queries": result.num_queries,
"result_type": result_type,
}
self.df = self.df.append(row, ignore_index=True)
self.row_list.append(row)
self._flushed = False

def flush(self):
self.df = pd.DataFrame.from_records(self.row_list)
self.df.to_csv(self.filename, quoting=csv.QUOTE_NONNUMERIC, index=False)
self._flushed = True

Expand Down

0 comments on commit 6978804

Please sign in to comment.