[GRASS-SVN] r70986 - grass-addons/grass7/raster/r.mregression.series

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 29 12:09:52 PDT 2017


Author: wenzeslaus
Date: 2017-04-29 12:09:52 -0700 (Sat, 29 Apr 2017)
New Revision: 70986

Modified:
   grass-addons/grass7/raster/r.mregression.series/r.mregression.series.py
Log:
r.mregression.series: lazy import statsmodels package (compilation now works without it)

Modified: grass-addons/grass7/raster/r.mregression.series/r.mregression.series.py
===================================================================
--- grass-addons/grass7/raster/r.mregression.series/r.mregression.series.py	2017-04-29 18:12:28 UTC (rev 70985)
+++ grass-addons/grass7/raster/r.mregression.series/r.mregression.series.py	2017-04-29 19:09:52 UTC (rev 70986)
@@ -49,6 +49,7 @@
 import numpy as np
 from numpy.linalg.linalg import LinAlgError
 
+# statsmodels lazy imported at the end of the file
 
 if "GISBASE" not in os.environ:
     sys.stderr.write("You must be in GRASS GIS to run this program.\n")
@@ -58,13 +59,6 @@
 from grass.pygrass import raster
 from grass.pygrass.gis.region import Region
 
-try:
-    import statsmodels.api as sm
-except ImportError:
-    grass.error("Cannot import statsmodels. Install python-statmodels package first")
-    sys.exit(1)
-
-
 CNULL = -2147483648  # null value for CELL maps
 FNULL = np.nan       # null value for FCELL and DCELL maps
 
@@ -264,4 +258,12 @@
 
 if __name__ == "__main__":
     options, flags = grass.parser()
+
+    # lazy import (global to avoid import in a loop)
+    try:
+        import statsmodels.api as sm
+    except ImportError:
+        grass.fatal(_("Cannot import statsmodels."
+                      " Install python-statmodels package first"))
+
     main(options, flags)



More information about the grass-commit mailing list