From 1ba3f3c62cccf43cc86b6c40f28466f1e86365ee Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 8 Dec 2020 13:44:31 -0600 Subject: [PATCH] CLN: use with instead of try finally in io/stata.py (#38326) Co-authored-by: VirosaLi <2EkF8qUgpNkj> --- pandas/io/stata.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pandas/io/stata.py b/pandas/io/stata.py index 6f296d3c8d92f..853a982536d40 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -1912,11 +1912,8 @@ def read_stata( if iterator or chunksize: return reader - try: - data = reader.read() - finally: - reader.close() - return data + with reader: + return reader.read() def _set_endianness(endianness: str) -> str: