summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorPieter Eendebak <pieter.eendebak@gmail.com>2023-01-25 21:48:43 +0100
committerGitHub <noreply@github.com>2023-01-25 21:48:43 +0100
commiteccd86a994fd4eb66696c05be7e5e3ca6e77d5e6 (patch)
treee5ad3ff8ba053a8b6038976eeec74ab42f2bf0d3 /numpy/lib
parentb97ca898a461889a5ed3397c4063da1395e029f0 (diff)
downloadnumpy-eccd86a994fd4eb66696c05be7e5e3ca6e77d5e6.tar.gz
DOC, ENH: Improve docstring of real_if_close (#23087)
* fix docstring of real_if_close * factor out dtype
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/type_check.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py
index 0dc014d76..3f84b80e5 100644
--- a/numpy/lib/type_check.py
+++ b/numpy/lib/type_check.py
@@ -2,7 +2,6 @@
"""
import functools
-import warnings
__all__ = ['iscomplexobj', 'isrealobj', 'imag', 'iscomplex',
'isreal', 'nan_to_num', 'real', 'real_if_close',
@@ -12,7 +11,7 @@ __all__ = ['iscomplexobj', 'isrealobj', 'imag', 'iscomplex',
from .._utils import set_module
import numpy.core.numeric as _nx
from numpy.core.numeric import asarray, asanyarray, isnan, zeros
-from numpy.core import overrides
+from numpy.core import overrides, getlimits
from .ufunclike import isneginf, isposinf
@@ -541,7 +540,8 @@ def real_if_close(a, tol=100):
Input array.
tol : float
Tolerance in machine epsilons for the complex part of the elements
- in the array.
+ in the array. If the tolerance is <=1, then the absolute tolerance
+ is used.
Returns
-------
@@ -572,11 +572,11 @@ def real_if_close(a, tol=100):
"""
a = asanyarray(a)
- if not issubclass(a.dtype.type, _nx.complexfloating):
+ type_ = a.dtype.type
+ if not issubclass(type_, _nx.complexfloating):
return a
if tol > 1:
- from numpy.core import getlimits
- f = getlimits.finfo(a.dtype.type)
+ f = getlimits.finfo(type_)
tol = f.eps * tol
if _nx.all(_nx.absolute(a.imag) < tol):
a = a.real