File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 1
1
import numpy
2
+ import warnings
2
3
from matplotlib .scale import ScaleBase
3
4
from matplotlib .ticker import (
4
5
FixedLocator ,
@@ -29,7 +30,9 @@ def _approx_erf(cls, x):
29
30
"""
30
31
31
32
guts = - x ** 2 * (4.0 / numpy .pi + cls ._A * x ** 2 ) / (1.0 + cls ._A * x ** 2 )
32
- return numpy .sign (x ) * numpy .sqrt (1.0 - numpy .exp (guts ))
33
+ with warnings .catch_warnings ():
34
+ warnings .filterwarnings ('ignore' , 'invalid value encountered in sign' )
35
+ return numpy .sign (x ) * numpy .sqrt (1.0 - numpy .exp (guts ))
33
36
34
37
@classmethod
35
38
def _approx_inv_erf (cls , z ):
@@ -41,7 +44,9 @@ def _approx_inv_erf(cls, z):
41
44
42
45
_b = (2 / numpy .pi / cls ._A ) + (0.5 * numpy .log (1 - z ** 2 ))
43
46
_c = numpy .log (1 - z ** 2 ) / cls ._A
44
- return numpy .sign (z ) * numpy .sqrt (numpy .sqrt (_b ** 2 - _c ) - _b )
47
+ with warnings .catch_warnings ():
48
+ warnings .filterwarnings ('ignore' , 'invalid value encountered in sign' )
49
+ return numpy .sign (z ) * numpy .sqrt (numpy .sqrt (_b ** 2 - _c ) - _b )
45
50
46
51
@classmethod
47
52
def ppf (cls , q ):
Original file line number Diff line number Diff line change @@ -72,6 +72,20 @@ def test_minimal_norm_cdf(mn, mn_input):
72
72
assert numpy .all (numpy .abs (diff ) < 0.001 )
73
73
74
74
75
+ def test_sign_with_nan_no_warning (mn ):
76
+ with pytest .warns (None ) as record :
77
+ res = mn ._approx_erf (numpy .nan )
78
+ assert not record
79
+ assert numpy .isnan (res )
80
+
81
+
82
+ def test_sign_with_nan_no_warning (mn ):
83
+ with pytest .warns (None ) as record :
84
+ res = mn ._approx_inv_erf (numpy .nan )
85
+ assert not record
86
+ assert numpy .isnan (res )
87
+
88
+
75
89
@pytest .mark .mpl_image_compare (
76
90
baseline_dir = 'baseline_images/test_probscale' ,
77
91
tolerance = TOLERANCE ,
You can’t perform that action at this time.
0 commit comments