Skip to content

DOC: catch warnings in test_feather & other #19407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pandas/io/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/io/test_feather.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" test feather-format compat """
from distutils.version import LooseVersion
from warnings import catch_warnings

import numpy as np

Expand Down Expand Up @@ -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):
Expand Down
32 changes: 9 additions & 23 deletions pandas/tests/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)


Expand Down
1 change: 1 addition & 0 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down