@@ -500,7 +500,8 @@ def print_assert_equal(test_string, actual, desired):
500
500
raise AssertionError (msg .getvalue ())
501
501
502
502
503
- def assert_almost_equal (actual , desired , decimal = 7 , err_msg = '' , verbose = True ):
503
+ def assert_almost_equal (actual , desired , decimal = 7 , err_msg = '' , verbose = True ,
504
+ * , precision = 6 ):
504
505
"""
505
506
Raises an AssertionError if two items are not equal up to desired
506
507
precision.
@@ -531,6 +532,10 @@ def assert_almost_equal(actual, desired, decimal=7, err_msg='', verbose=True):
531
532
The error message to be printed in case of failure.
532
533
verbose : bool, optional
533
534
If True, the conflicting values are appended to the error message.
535
+ precision : int or None, optional
536
+ Number of digits of precision for floating point output (default 6).
537
+ May be None if `floatmode` is not `fixed`, to print as many digits as
538
+ necessary to uniquely specify the value (see `np.set_printoptions()`).
534
539
535
540
Raises
536
541
------
@@ -600,14 +605,14 @@ def _build_err_msg():
600
605
desiredr = desired
601
606
desiredi = 0
602
607
try :
603
- ass
8000
ert_almost_equal (actualr , desiredr , decimal = decimal )
604
- assert_almost_equal (actuali , desiredi , decimal = decimal )
608
+ assert_almost_equal (actualr , desiredr , decimal = decimal , precision = precision )
609
+ assert_almost_equal (actuali , desiredi , decimal = decimal , precision = precision )
605
610
except AssertionError :
606
611
raise AssertionError (_build_err_msg ())
607
612
608
613
if isinstance (actual , (ndarray , tuple , list )) \
609
614
or isinstance (desired , (ndarray , tuple , list )):
610
- return assert_array_almost_equal (actual , desired , decimal , err_msg )
615
+ return assert_array_almost_equal (actual , desired , decimal , err_msg , precision = precision )
611
616
try :
612
617
# If one of desired/actual is not finite, handle it specially here:
613
618
# check that both are nan if any is a nan, and test for equality
@@ -925,7 +930,7 @@ def func_assert_same_pos(x, y, func=isnan, hasval='nan'):
925
930
926
931
927
932
def assert_array_equal (actual , desired , err_msg = '' , verbose = True , * ,
928
- strict = False ):
933
+ precision = 6 , strict = False ):
929
934
"""
930
935
Raises an AssertionError if two array_like objects are not equal.
931
936
@@ -960,6 +965,10 @@ def assert_array_equal(actual, desired, err_msg='', verbose=True, *,
960
965
The error message to be printed in case of failure.
961
966
verbose : bool, optional
962
967
If True, the conflicting values are appended to the error message.
968
+ precision : int or None, optional
969
+ Number of digits of precision for floating point output (default 6).
970
+ May be None if `floatmode` is not `fixed`, to print as many digits as
971
+ necessary to uniquely specify the value (see `np.set_printoptions()`).
963
972
strict : bool, optional
964
973
If True, raise an AssertionError when either the shape or the data
965
974
type of the array_like objects does not match. The special
@@ -1050,11 +1059,11 @@ def assert_array_equal(actual, desired, err_msg='', verbose=True, *,
1050
1059
__tracebackhide__ = True # Hide traceback for py.test
1051
1060
assert_array_compare (operator .__eq__ , actual , desired , err_msg = err_msg ,
1052
1061
verbose = verbose , header = 'Arrays are not equal' ,
1053
- strict = strict )
1062
+ precision = precision , strict = strict )
1054
1063
1055
1064
1056
1065
def assert_array_almost_equal (actual , desired , decimal = 6 , err_msg = '' ,
1057
8000
- verbose = True ):
1066
+ verbose = True , * , precision = 6 ):
1058
1067
"""
1059
1068
Raises an AssertionError if two objects are not equal up to desired
1060
1069
precision.
@@ -1087,6 +1096,10 @@ def assert_array_almost_equal(actual, desired, decimal=6, err_msg='',
1087
1096
The error message to be printed in case of failure.
1088
1097
verbose : bool, optional
1089
1098
If True, the conflicting values are appended to the error message.
1099
+ precision : int or None, optional
1100
+ Number of digits of precision for floating point output (default 6).
1101
+ May be None if `floatmode` is not `fixed`, to print as many digits as
1102
+ necessary to uniquely specify the value (see `np.set_printoptions()`).
1090
1103
1091
1104
Raises
1092
1105
------
@@ -1162,13 +1175,15 @@ def compare(x, y):
1162
1175
1163
1176
return z < 1.5 * 10.0 ** (- decimal )
1164
1177
1178
+ header = ('Arrays are not almost equal to %d decimals' % decimal )
1165
1179
assert_array_compare (compare , actual , desired , err_msg = err_msg ,
1166
1180
verbose = verbose ,
1167
- header = ( 'Arrays are not almost equal to %d decimals' % decimal ) ,
1168
- precision = decimal )
1181
+ header = header ,
1182
+ precision = precision )
1169
1183
1170
1184
1171
- def assert_array_less (x , y , err_msg = '' , verbose = True , * , strict = False ):
1185
+ def assert_array_less (x , y , err_msg = '' , verbose = True , * , precision = 6 ,
1186
+ strict = False ):
1172
1187
"""
1173
1188
Raises an AssertionError if two array_like objects are not ordered by less
1174
1189
than.
@@ -1190,6 +1205,10 @@ def assert_array_less(x, y, err_msg='', verbose=True, *, strict=False):
1190
1205
The error message to be printed in case of failure.
1191
1206
verbose : bool
1192
1207
If True, the conflicting values are appended to the error message.
1208
+ precision : int or None, optional
1209
+ Number of digits of precision for floating point output (default 6).
1210
+ May be None if `floatmode` is not `fixed`, to print as many digits as
1211
+ necessary to uniquely specify the value (see `np.set_printoptions()`).
1193
1212
strict : bool, optional
1194
1213
If True, raise an AssertionError when either the shape or the data
1195
1214
type of the array_like objects does not match. The special
@@ -1278,6 +1297,7 @@ def assert_array_less(x, y, err_msg='', verbose=True, *, strict=False):
1278
1297
assert_array_compare (operator .__lt__ , x , y , err_msg = err_msg ,
1279
1298
verbose = verbose ,
1280
1299
header = 'Arrays are not strictly ordered `x < y`' ,
1300
+ precision = precision ,
1281
1301
equal_inf = False ,
1282
1302
strict = strict ,
1283
1303
names = ('x' , 'y' ))
@@ -1602,7 +1622,7 @@ def _assert_valid_refcount(op):
1602
1622
1603
1623
1604
1624
def assert_allclose (actual , desired , rtol = 1e-7 , atol = 0 , equal_nan = True ,
1605
- err_msg = '' , verbose = True , * , strict = False ):
1625
+ err_msg = '' , verbose = True , * , precision = 6 , strict = False ):
1606
1626
"""
1607
1627
Raises an AssertionError if two objects are not equal up to desired
1608
1628
tolerance.
@@ -1633,6 +1653,10 @@ def assert_allclose(actual, desired, rtol=1e-7, atol=0, equal_nan=True,
1633
1653
The error message to be printed in case of failure.
1634
1654
verbose : bool, optional
1635
1655
If True, the conflicting values are appended to the error message.
1656
+ precision : int or None, optional
1657
+ Number of digits of precision for floating point output (default 6).
1658
+ May be None if `floatmode` is not `fixed`, to print as many digits as
1659
+ necessary to uniquely specify the value (see `np.set_printoptions()`).
1636
1660
strict : bool, optional
1637
1661
If True, raise an ``AssertionError`` when either the shape or the data
1638
1662
type of the arguments does not match. The special handling of scalars
@@ -1706,8 +1730,8 @@ def compare(x, y):
1706
1730
actual , desired = np .asanyarray (actual ), np .asanyarray (desired )
1707
1731
header = f'Not equal to tolerance rtol={ rtol :g} , atol={ atol :g} '
1708
1732
assert_array_compare (compare , actual , desired , err_msg = str (err_msg ),
1709
- verbose = verbose , header = header , equal_nan = equal_nan ,
1710
- strict = strict )
1733
+ verbose = verbose , header = header , precision = precision ,
1734
+ equal_nan = equal_nan , strict = strict )
1711
1735
1712
1736
1713
1737
def assert_array_almost_equal_nulp (x , y , nulp = 1 ):
0 commit comments