Skip to content

Commit 8a7aca9

Browse files
authored
DOC: catch warnings in test_feather (pandas-dev#19407)
1 parent 68cdd46 commit 8a7aca9

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

pandas/io/parquet.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ def read(self, path, columns=None, **kwargs):
215215
# We need to retain the original path(str) while also
216216
# pass the S3File().open function to fsatparquet impl.
217217
s3, _, _ = get_filepath_or_buffer(path)
218-
parquet_file = self.api.ParquetFile(path, open_with=s3.s3.open)
218+
try:
219+
parquet_file = self.api.ParquetFile(path, open_with=s3.s3.open)
220+
finally:
221+
s3.close()
219222
else:
220223
path, _, _ = get_filepath_or_buffer(path)
221224
parquet_file = self.api.ParquetFile(path)

pandas/tests/io/test_feather.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" test feather-format compat """
22
from distutils.version import LooseVersion
3+
from warnings import catch_warnings
34

45
import numpy as np
56

@@ -31,7 +32,9 @@ def check_round_trip(self, df, **kwargs):
3132

3233
with ensure_clean() as path:
3334
to_feather(df, path)
34-
result = read_feather(path, **kwargs)
35+
36+
with catch_warnings(record=True):
37+
result = read_feather(path, **kwargs)
3538
assert_frame_equal(result, df)
3639

3740
def test_error(self):

pandas/tests/io/test_parquet.py

+9-23
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ def check_round_trip(df, engine=None, path=None,
148148
def compare(repeat):
149149
for _ in range(repeat):
150150
df.to_parquet(path, **write_kwargs)
151-
actual = read_parquet(path, **read_kwargs)
151+
with catch_warnings(record=True):
152+
actual = read_parquet(path, **read_kwargs)
152153
tm.assert_frame_equal(expected, actual,
153154
check_names=check_names)
154155

@@ -228,35 +229,20 @@ def test_cross_engine_fp_pa(df_cross_compat, pa, fp):
228229
with tm.ensure_clean() as path:
229230
df.to_parquet(path, engine=fp, compression=None)
230231

231-
result = read_parquet(path, engine=pa)
232-
tm.assert_frame_equal(result, df)
233-
234-
result = read_parquet(path, engine=pa, columns=['a', 'd'])
235-
tm.assert_frame_equal(result, df[['a', 'd']])
236-
237-
238-
def check_round_trip_equals(df, path, engine,
239-
write_kwargs, read_kwargs,
240-
expected, check_names):
241-
242-
df.to_parquet(path, engine, **write_kwargs)
243-
actual = read_parquet(path, engine, **read_kwargs)
244-
tm.assert_frame_equal(expected, actual,
245-
check_names=check_names)
232+
with catch_warnings(record=True):
233+
result = read_parquet(path, engine=pa)
234+
tm.assert_frame_equal(result, df)
246235

247-
# repeat
248-
df.to_parquet(path, engine, **write_kwargs)
249-
actual = read_parquet(path, engine, **read_kwargs)
250-
tm.assert_frame_equal(expected, actual,
251-
check_names=check_names)
236+
result = read_parquet(path, engine=pa, columns=['a', 'd'])
237+
tm.assert_frame_equal(result, df[['a', 'd']])
252238

253239

254240
class Base(object):
255241

256242
def check_error_on_write(self, df, engine, exc):
257243
# check that we are raising the exception on writing
258-
with pytest.raises(exc):
259-
with tm.ensure_clean() as path:
244+
with tm.ensure_clean() as path:
245+
with pytest.raises(exc):
260246
to_parquet(df, path, engine, compression=None)
261247

262248

pandas/util/testing.py

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def decompress_file(path, compression):
205205
raise ValueError(msg)
206206

207207
yield f
208+
f.close()
208209

209210

210211
def assert_almost_equal(left, right, check_exact=False,

0 commit comments

Comments
 (0)