[GRASS-SVN] r68211 - grass-addons/grass7/raster/r.randomforest

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Apr 4 12:35:51 PDT 2016


Author: wenzeslaus
Date: 2016-04-04 12:35:51 -0700 (Mon, 04 Apr 2016)
New Revision: 68211

Modified:
   grass-addons/grass7/raster/r.randomforest/r.randomforest.py
Log:
r.randomforest: lazy import in main instead of global import, so it generates info for addons

Modified: grass-addons/grass7/raster/r.randomforest/r.randomforest.py
===================================================================
--- grass-addons/grass7/raster/r.randomforest/r.randomforest.py	2016-04-04 19:26:09 UTC (rev 68210)
+++ grass-addons/grass7/raster/r.randomforest/r.randomforest.py	2016-04-04 19:35:51 UTC (rev 68211)
@@ -154,16 +154,6 @@
                       " Exiting").format(module_name))
         return False
 
-if module_exists("sklearn") == True:
-    from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
-    from sklearn.externals import joblib
-else:
-    exit()
-if module_exists("pandas") == True:
-    import pandas as pd
-else:
-    exit()
-
 def cleanup():
     # We can then close the rasters and the roi image
     for i in range(nbands): rasstack[i].close()
@@ -217,6 +207,17 @@
         print("Cannot save and load a model at the same time")
         exit()
 
+    # lazy imports
+    if module_exists("sklearn") == True:
+        from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
+        from sklearn.externals import joblib
+    else:
+        exit()
+    if module_exists("pandas") == True:
+        import pandas as pd
+    else:
+        exit()
+
     ######################  Fetch individual raster names from group ###############################
     groupmaps = grass.read_command("i.group", group=igroup, flags="g")
     groupmaps = normalize_newlines(groupmaps)



More information about the grass-commit mailing list