diff --git a/pandas/io/parquet.py b/pandas/io/parquet.py index 4508d5c1e1781..6e1b6e14861c3 100644 --- a/pandas/io/parquet.py +++ b/pandas/io/parquet.py @@ -215,7 +215,10 @@ def read(self, path, columns=None, **kwargs): # We need to retain the original path(str) while also # pass the S3File().open function to fsatparquet impl. s3, _, _ = get_filepath_or_buffer(path) - parquet_file = self.api.ParquetFile(path, open_with=s3.s3.open) + try: + parquet_file = self.api.ParquetFile(path, open_with=s3.s3.open) + finally: + s3.close() else: path, _, _ = get_filepath_or_buffer(path) parquet_file = self.api.ParquetFile(path) diff --git a/pandas/tests/io/test_feather.py b/pandas/tests/io/test_feather.py index e9909400ce429..9d04111d64125 100644 --- a/pandas/tests/io/test_feather.py +++ b/pandas/tests/io/test_feather.py @@ -1,5 +1,6 @@ """ test feather-format compat """ from distutils.version import LooseVersion +from warnings import catch_warnings import numpy as np @@ -31,7 +32,9 @@ def check_round_trip(self, df, **kwargs): with ensure_clean() as path: to_feather(df, path) - result = read_feather(path, **kwargs) + + with catch_warnings(record=True): + result = read_feather(path, **kwargs) assert_frame_equal(result, df) def test_error(self): diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index 8a6a22abe23fa..6c172c80514e7 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -148,7 +148,8 @@ def check_round_trip(df, engine=None, path=None, def compare(repeat): for _ in range(repeat): df.to_parquet(path, **write_kwargs) - actual = read_parquet(path, **read_kwargs) + with catch_warnings(record=True): + actual = read_parquet(path, **read_kwargs) tm.assert_frame_equal(expected, actual, check_names=check_names) @@ -228,35 +229,20 @@ def test_cross_engine_fp_pa(df_cross_compat, pa, fp): with tm.ensure_clean() as path: df.to_parquet(path, engine=fp, compression=None) - result = read_parquet(path, engine=pa) - tm.assert_frame_equal(result, df) - - result = read_parquet(path, engine=pa, columns=['a', 'd']) - tm.assert_frame_equal(result, df[['a', 'd']]) - - -def check_round_trip_equals(df, path, engine, - write_kwargs, read_kwargs, - expected, check_names): - - df.to_parquet(path, engine, **write_kwargs) - actual = read_parquet(path, engine, **read_kwargs) - tm.assert_frame_equal(expected, actual, - check_names=check_names) + with catch_warnings(record=True): + result = read_parquet(path, engine=pa) + tm.assert_frame_equal(result, df) - # repeat - df.to_parquet(path, engine, **write_kwargs) - actual = read_parquet(path, engine, **read_kwargs) - tm.assert_frame_equal(expected, actual, - check_names=check_names) + result = read_parquet(path, engine=pa, columns=['a', 'd']) + tm.assert_frame_equal(result, df[['a', 'd']]) class Base(object): def check_error_on_write(self, df, engine, exc): # check that we are raising the exception on writing - with pytest.raises(exc): - with tm.ensure_clean() as path: + with tm.ensure_clean() as path: + with pytest.raises(exc): to_parquet(df, path, engine, compression=None) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 34e634f56aec6..941bdcbc8b064 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -205,6 +205,7 @@ def decompress_file(path, compression): raise ValueError(msg) yield f + f.close() def assert_almost_equal(left, right, check_exact=False,