|
23 | 23 | import numpy as np
|
24 | 24 |
|
25 | 25 | import pandas as pd
|
26 |
| -from pandas.core.common import _is_sequence |
| 26 | +from pandas.core.common import _is_sequence, array_equivalent |
27 | 27 | import pandas.core.index as index
|
28 | 28 | import pandas.core.series as series
|
29 | 29 | import pandas.core.frame as frame
|
@@ -86,10 +86,31 @@ def reset_display_options(self):
|
86 | 86 | pd.reset_option('^display.',silent=True)
|
87 | 87 |
|
88 | 88 | def assert_numpy_array_equal(self, np_array, assert_equal):
|
| 89 | + """Checks that 'np_array' is equal to 'assert_equal' |
| 90 | +
|
| 91 | + Note that the expected array should not contain `np.nan`! Two numpy arrays are equal if all |
| 92 | + elements are equal, which is not possible if `np.nan` is such an element! |
| 93 | +
|
| 94 | + If the expected array includes `np.nan` use `assert_numpy_array_equivalent(...)`. |
| 95 | + """ |
89 | 96 | if np.array_equal(np_array, assert_equal):
|
90 | 97 | return
|
91 | 98 | raise AssertionError('{0} is not equal to {1}.'.format(np_array, assert_equal))
|
92 | 99 |
|
| 100 | + def assert_numpy_array_equivalent(self, np_array, assert_equal): |
| 101 | + """Checks that 'np_array' is equivalent to 'assert_equal' |
| 102 | +
|
| 103 | + Two numpy arrays are equivalent if the arrays have equal non-NaN elements, and |
| 104 | + `np.nan` in corresponding locations. |
| 105 | +
|
| 106 | + If the the expected array does not contain `np.nan` `assert_numpy_array_equivalent` is the |
| 107 | + similar to `assert_numpy_array_equal()`. If the expected array includes `np.nan` use this |
| 108 | + function. |
| 109 | + """ |
| 110 | + if array_equivalent(np_array, assert_equal): |
| 111 | + return |
| 112 | + raise AssertionError('{0} is not equivalent to {1}.'.format(np_array, assert_equal)) |
| 113 | + |
93 | 114 | def assertIs(self, first, second, msg=''):
|
94 | 115 | """Checks that 'first' is 'second'"""
|
95 | 116 | a, b = first, second
|
|
0 commit comments