From 35a3dc4146ebf6326920af08a0863b128a02ae2b Mon Sep 17 00:00:00 2001 From: Aly Sivji Date: Sat, 19 May 2018 18:04:45 -0500 Subject: [PATCH] Refactor to use context managers --- pandas/tests/io/test_packers.py | 5 ++--- pandas/tests/series/test_io.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pandas/tests/io/test_packers.py b/pandas/tests/io/test_packers.py index cfac77291803d..0b1c1ca178762 100644 --- a/pandas/tests/io/test_packers.py +++ b/pandas/tests/io/test_packers.py @@ -128,9 +128,8 @@ def test_string_io(self): with ensure_clean(self.path) as p: s = df.to_msgpack() - fh = open(p, 'wb') - fh.write(s) - fh.close() + with open(p, 'wb') as fh: + fh.write(s) result = read_msgpack(p) tm.assert_frame_equal(result, df) diff --git a/pandas/tests/series/test_io.py b/pandas/tests/series/test_io.py index 0b0d4334c86a3..e369dfda6deac 100644 --- a/pandas/tests/series/test_io.py +++ b/pandas/tests/series/test_io.py @@ -75,9 +75,8 @@ def test_from_csv(self): series_h = self.read_csv(path, header=0) assert series_h.name == "series" - outfile = open(path, "w") - outfile.write("1998-01-01|1.0\n1999-01-01|2.0") - outfile.close() + with open(path, "w") as outfile: + outfile.write("1998-01-01|1.0\n1999-01-01|2.0") series = self.read_csv(path, sep="|") check_series = Series({datetime(1998, 1, 1): 1.0,