Skip to content

Instantly share code, notes, and snippets.

@elmotec
Last active April 19, 2018 01:26
Show Gist options
  • Save elmotec/f127e8536d6895280ce72d79c14a354b to your computer and use it in GitHub Desktop.
Save elmotec/f127e8536d6895280ce72d79c14a354b to your computer and use it in GitHub Desktop.
Handles pandas.DataFrame in unittest.TestCase.assertEqual()
def add_data_frame_equality_func(test):
"""Define test class to handle assertEqual with `pandas.DataFrame`."""
def frame_equal(lhs, rhs, msg=None):
"""Adapter for pandas.testing.assert_frame_equal."""
if msg:
try:
pdt.assert_frame_equal(lhs, rhs)
except AssertionError as err:
raise test.failureException(msg)
else:
pdt.assert_frame_equal(lhs, rhs)
test.addTypeEqualityFunc(pd.DataFrame, frame_equal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment