Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.9/dist-packages/scipy/__init__.py: 73%

44 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-23 06:43 +0000

1""" 

2SciPy: A scientific computing package for Python 

3================================================ 

4 

5Documentation is available in the docstrings and 

6online at https://docs.scipy.org. 

7 

8Subpackages 

9----------- 

10Using any of these subpackages requires an explicit import. For example, 

11``import scipy.cluster``. 

12 

13:: 

14 

15 cluster --- Vector Quantization / Kmeans 

16 constants --- Physical and mathematical constants and units 

17 datasets --- Dataset methods 

18 fft --- Discrete Fourier transforms 

19 fftpack --- Legacy discrete Fourier transforms 

20 integrate --- Integration routines 

21 interpolate --- Interpolation Tools 

22 io --- Data input and output 

23 linalg --- Linear algebra routines 

24 misc --- Utilities that don't have another home. 

25 ndimage --- N-D image package 

26 odr --- Orthogonal Distance Regression 

27 optimize --- Optimization Tools 

28 signal --- Signal Processing Tools 

29 sparse --- Sparse Matrices 

30 spatial --- Spatial data structures and algorithms 

31 special --- Special functions 

32 stats --- Statistical Functions 

33 

34Public API in the main SciPy namespace 

35-------------------------------------- 

36:: 

37 

38 __version__ --- SciPy version string 

39 LowLevelCallable --- Low-level callback function 

40 show_config --- Show scipy build configuration 

41 test --- Run scipy unittests 

42 

43""" 

44 

45from numpy import __version__ as __numpy_version__ 

46 

47# We first need to detect if we're being called as part of the SciPy 

48# setup procedure itself in a reliable manner. 

49try: 

50 __SCIPY_SETUP__ 

51except NameError: 

52 __SCIPY_SETUP__ = False 

53 

54 

55if __SCIPY_SETUP__: 

56 import sys 

57 sys.stderr.write('Running from SciPy source directory.\n') 

58 del sys 

59else: 

60 try: 

61 from scipy.__config__ import show as show_config 

62 except ImportError as e: 

63 msg = """Error importing SciPy: you cannot import SciPy while 

64 being in scipy source directory; please exit the SciPy source 

65 tree first and relaunch your Python interpreter.""" 

66 raise ImportError(msg) from e 

67 

68 from scipy.version import version as __version__ 

69 

70 # Allow distributors to run custom init code 

71 from . import _distributor_init 

72 del _distributor_init 

73 

74 from scipy._lib import _pep440 

75 # In maintenance branch, change to np_maxversion N+3 if numpy is at N 

76 # See setup.py for more details 

77 np_minversion = '1.22.4' 

78 np_maxversion = '9.9.99' 

79 if (_pep440.parse(__numpy_version__) < _pep440.Version(np_minversion) or 

80 _pep440.parse(__numpy_version__) >= _pep440.Version(np_maxversion)): 

81 import warnings 

82 warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}" 

83 f" is required for this version of SciPy (detected " 

84 f"version {__numpy_version__})", 

85 UserWarning) 

86 del _pep440 

87 

88 # This is the first import of an extension module within SciPy. If there's 

89 # a general issue with the install, such that extension modules are missing 

90 # or cannot be imported, this is where we'll get a failure - so give an 

91 # informative error message. 

92 try: 

93 from scipy._lib._ccallback import LowLevelCallable 

94 except ImportError as e: 

95 msg = "The `scipy` install you are using seems to be broken, " + \ 

96 "(extension modules cannot be imported), " + \ 

97 "please try reinstalling." 

98 raise ImportError(msg) from e 

99 

100 from scipy._lib._testutils import PytestTester 

101 test = PytestTester(__name__) 

102 del PytestTester 

103 

104 submodules = [ 

105 'cluster', 

106 'constants', 

107 'datasets', 

108 'fft', 

109 'fftpack', 

110 'integrate', 

111 'interpolate', 

112 'io', 

113 'linalg', 

114 'misc', 

115 'ndimage', 

116 'odr', 

117 'optimize', 

118 'signal', 

119 'sparse', 

120 'spatial', 

121 'special', 

122 'stats' 

123 ] 

124 

125 __all__ = submodules + [ 

126 'LowLevelCallable', 

127 'test', 

128 'show_config', 

129 '__version__', 

130 ] 

131 

132 def __dir__(): 

133 return __all__ 

134 

135 import importlib as _importlib 

136 

137 def __getattr__(name): 

138 if name in submodules: 

139 return _importlib.import_module(f'scipy.{name}') 

140 else: 

141 try: 

142 return globals()[name] 

143 except KeyError: 

144 raise AttributeError( 

145 f"Module 'scipy' has no attribute '{name}'" 

146 )