From 7ef04d15c12a86cfe7c7c4cc154915839c86bd71 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Tue, 10 Nov 2020 17:54:26 +0700 Subject: [PATCH 1/2] TYP: fix mypy ignored err in pandas/io/formats/format.py --- pandas/io/formats/format.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 5b69ef4eba26e..8a2148881c90f 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1049,9 +1049,10 @@ def to_csv( created_buffer = path_or_buf is None if created_buffer: path_or_buf = StringIO() + assert path_or_buf is not None csv_formatter = CSVFormatter( - path_or_buf=path_or_buf, # type: ignore[arg-type] + path_or_buf=path_or_buf, line_terminator=line_terminator, sep=sep, encoding=encoding, From 050d0dab9e6d2be27dc65f929f81f56a6e76eb63 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov <41443370+ivanovmg@users.noreply.github.com> Date: Tue, 10 Nov 2020 21:22:24 +0700 Subject: [PATCH 2/2] REF: implement suggestion Co-authored-by: Simon Hawkins --- pandas/io/formats/format.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 8a2148881c90f..e4bd1eddbc5f8 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1046,10 +1046,11 @@ def to_csv( """ from pandas.io.formats.csvs import CSVFormatter - created_buffer = path_or_buf is None - if created_buffer: + if path_or_buf is None: + created_buffer = True path_or_buf = StringIO() - assert path_or_buf is not None + else: + created_buffer = False csv_formatter = CSVFormatter( path_or_buf=path_or_buf,