Skip to content

TST: Moving testing method outside of TestCase #8104

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

Closed
wants to merge 2 commits into from
Closed
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
37 changes: 31 additions & 6 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def assert_numpy_array_equal(self, np_array, assert_equal):

If the expected array includes `np.nan` use `assert_numpy_array_equivalent(...)`.
"""
if np.array_equal(np_array, assert_equal):
return
raise AssertionError('{0} is not equal to {1}.'.format(np_array, assert_equal))
return assert_numpy_array_equal(np_array, assert_equal)

def round_trip_pickle(self, obj, path=None):
if path is None:
Expand All @@ -115,9 +113,8 @@ def assert_numpy_array_equivalent(self, np_array, assert_equal, strict_nan=False
similar to `assert_numpy_array_equal()`. If the expected array includes `np.nan` use this
function.
"""
if array_equivalent(np_array, assert_equal, strict_nan=strict_nan):
return
raise AssertionError('{0} is not equivalent to {1}.'.format(np_array, assert_equal))
return assert_numpy_array_equivalent(np_array, assert_equal, strict_nan)


def assertIs(self, first, second, msg=''):
"""Checks that 'first' is 'second'"""
Expand Down Expand Up @@ -586,6 +583,34 @@ def isiterable(obj):
def is_sorted(seq):
return assert_almost_equal(seq, np.sort(np.array(seq)))

def assert_numpy_array_equal(np_array, assert_equal):
"""Checks that 'np_array' is equal to 'assert_equal'

Note that the expected array should not contain `np.nan`! Two numpy arrays are equal if all
elements are equal, which is not possible if `np.nan` is such an element!

If the expected array includes `np.nan` use `assert_numpy_array_equivalent(...)`.
"""
if np.array_equal(np_array, assert_equal):
return
raise AssertionError('{0} is not equal to {1}.'.format(np_array, assert_equal))


def assert_numpy_array_equivalent(np_array, assert_equal, strict_nan=False):
"""Checks that 'np_array' is equivalent to 'assert_equal'

Two numpy arrays are equivalent if the arrays have equal non-NaN elements, and
`np.nan` in corresponding locations.

If the the expected array does not contain `np.nan` `assert_numpy_array_equivalent` is the
similar to `assert_numpy_array_equal()`. If the expected array includes `np.nan` use this
function.
"""
if array_equivalent(np_array, assert_equal, strict_nan=strict_nan):
return True
raise AssertionError('{0} is not equivalent to {1}.'.format(np_array, assert_equal))


# This could be refactored to use the NDFrame.equals method
def assert_series_equal(left, right, check_dtype=True,
check_index_type=False,
Expand Down