Skip to content

TST: catch warnings on Panel #19068

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 4, 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
23 changes: 23 additions & 0 deletions pandas/tests/generic/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,26 @@ def test_to_xarray(self):

# idempotency
assert_panel_equal(result.to_pandas(), p)


# run all the tests, but wrap each in a warning catcher
for t in ['test_rename', 'test_get_numeric_data',
'test_get_default', 'test_nonzero',
'test_downcast', 'test_constructor_compound_dtypes',
'test_head_tail',
'test_size_compat', 'test_split_compat',
'test_unexpected_keyword',
'test_stat_unexpected_keyword', 'test_api_compat',
'test_stat_non_defaults_args',
'test_truncate_out_of_bounds',
'test_metadata_propagation', 'test_copy_and_deepcopy',
'test_sample']:

def f():
def tester(self):
f = getattr(super(TestPanel, self), t)
with catch_warnings(record=True):
f()
return tester

setattr(TestPanel, t, f())
28 changes: 11 additions & 17 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import traceback

from datetime import datetime
from functools import wraps, partial
from functools import wraps
from contextlib import contextmanager

from numpy.random import randn, rand
Expand Down Expand Up @@ -1266,14 +1266,13 @@ def assert_frame_equal(left, right, check_dtype=True,
obj='DataFrame.iloc[:, {idx}]'.format(idx=i))


def assert_panelnd_equal(left, right,
check_dtype=True,
check_panel_type=False,
check_less_precise=False,
assert_func=assert_frame_equal,
check_names=False,
by_blocks=False,
obj='Panel'):
def assert_panel_equal(left, right,
check_dtype=True,
check_panel_type=False,
check_less_precise=False,
check_names=False,
by_blocks=False,
obj='Panel'):
"""Check that left and right Panels are equal.

Parameters
Expand All @@ -1288,7 +1287,6 @@ def assert_panelnd_equal(left, right,
Specify comparison precision. Only used when check_exact is False.
5 digits (False) or 3 digits (True) after decimal points are compared.
If int, then specify the digits to compare
assert_func : function for comparing data
check_names : bool, default True
Whether to check the Index names attribute.
by_blocks : bool, default False
Expand Down Expand Up @@ -1322,19 +1320,15 @@ def assert_panelnd_equal(left, right,
assert item in right, msg
litem = left.iloc[i]
ritem = right.iloc[i]
assert_func(litem, ritem, check_less_precise=check_less_precise)
assert_frame_equal(litem, ritem,
check_less_precise=check_less_precise,
check_names=check_names)

for i, item in enumerate(right._get_axis(0)):
msg = "non-matching item (left) '{item}'".format(item=item)
assert item in left, msg


# TODO: strangely check_names fails in py3 ?
_panel_frame_equal = partial(assert_frame_equal, check_names=False)
assert_panel_equal = partial(assert_panelnd_equal,
assert_func=_panel_frame_equal)


# -----------------------------------------------------------------------------
# Sparse

Expand Down