From 222a69ca49806d9835fde3691bf01c65b6fb10eb Mon Sep 17 00:00:00 2001 From: hsuehch <34030441+hsuehch@users.noreply.github.com> Date: Sat, 18 Dec 2021 23:04:33 +0900 Subject: [PATCH] Eliminate extra empty lines in CSV monitor files on Windows (DLR-RM#692) (#695) * Added ``newline="\n"`` when opening CSV monitor files so that each line ends with ``\r\n`` instead of ``\r\r\n`` on Windows while Linux environments are not affected --- docs/misc/changelog.rst | 3 ++- stable_baselines3/common/monitor.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/misc/changelog.rst b/docs/misc/changelog.rst index 90a2060..d60e722 100644 --- a/docs/misc/changelog.rst +++ b/docs/misc/changelog.rst @@ -37,6 +37,7 @@ Others: ^^^^^^^ - Added a warning in the env checker when not using ``np.float32`` for continuous actions - Improved test coverage and error message when checking shape of observation +- Added ``newline="\n"`` when opening CSV monitor files so that each line ends with ``\r\n`` instead of ``\r\r\n`` on Windows while Linux environments are not affected (@hsuehch) Documentation: ^^^^^^^^^^^^^^ @@ -852,4 +853,4 @@ And all the contributors: @ShangqunYu @PierreExeter @JacopoPan @ltbd78 @tom-doerr @Atlis @liusida @09tangriro @amy12xx @juancroldan @benblack769 @bstee615 @c-rizz @skandermoalla @MihaiAnca13 @davidblom603 @ayeright @cyprienc @wkirgsn @AechPro @CUN-bjy @batu @IljaAvadiev @timokau @kachayev @cleversonahum -@eleurent @ac-93 @cove9988 @theDebugger811 +@eleurent @ac-93 @cove9988 @theDebugger811 @hsuehch diff --git a/stable_baselines3/common/monitor.py b/stable_baselines3/common/monitor.py index d239627..7b51761 100644 --- a/stable_baselines3/common/monitor.py +++ b/stable_baselines3/common/monitor.py @@ -178,7 +178,7 @@ class ResultsWriter: filename = os.path.join(filename, Monitor.EXT) else: filename = filename + "." + Monitor.EXT - self.file_handler = open(filename, "wt") + self.file_handler = open(filename, "wt", newline="\n") self.file_handler.write("#%s\n" % json.dumps(header)) self.logger = csv.DictWriter(self.file_handler, fieldnames=("r", "l", "t") + extra_keys) self.logger.writeheader()