Index: branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionPythonFormatter.cs
===================================================================
--- branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionPythonFormatter.cs	(revision 17855)
+++ branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionPythonFormatter.cs	(revision 17860)
@@ -36,5 +36,8 @@
 
     private int VariableCounter { get; set; } = 0;
-    private IDictionary<string, string> VariableMap = new Dictionary<string, string>();
+    private IDictionary<string, string> VariableMap { get; } = new Dictionary<string, string>();
+    private int MathLibCounter { get; set; } = 0;
+    private int StatisticLibCounter { get; set; } = 0;
+    private int EvaluateIfCounter { get; set; } = 0;
 
     [StorableConstructor]
@@ -65,16 +68,21 @@
 
     private void GenerateImports(StringBuilder strBuilder) {
-      strBuilder.AppendLine("# imports");
-      strBuilder.AppendLine("import math");
-      strBuilder.AppendLine("import statistics");
+      if(MathLibCounter > 0 || StatisticLibCounter > 0)
+        strBuilder.AppendLine("# imports");
+      if(MathLibCounter > 0)
+        strBuilder.AppendLine("import math");
+      if(StatisticLibCounter > 0)
+        strBuilder.AppendLine("import statistics");
     }
 
     private void GenerateIfThenElseSource(StringBuilder strBuilder) {
-      strBuilder.AppendLine("# condition helper function");
-      strBuilder.AppendLine("def evaluate_if(condition, then_path, else_path): ");
-      strBuilder.AppendLine("\tif condition:");
-      strBuilder.AppendLine("\t\treturn then_path");
-      strBuilder.AppendLine("\telse:");
-      strBuilder.AppendLine("\t\treturn else_path");
+      if(EvaluateIfCounter > 0) {
+        strBuilder.AppendLine("# condition helper function");
+        strBuilder.AppendLine("def evaluate_if(condition, then_path, else_path): ");
+        strBuilder.AppendLine("\tif condition:");
+        strBuilder.AppendLine("\t\treturn then_path");
+        strBuilder.AppendLine("\telse:");
+        strBuilder.AppendLine("\t\treturn else_path");
+      }
     }
 
@@ -110,18 +118,23 @@
         FormatNode(node, strBuilder, infixSymbol: " and ");
       } else if (symbol is Average) {
+        StatisticLibCounter++;
         FormatNode(node, strBuilder, prefixSymbol: "statistics.mean", openingSymbol: "([", closingSymbol: "])");
       } else if (symbol is Cosine) {
+        MathLibCounter++;
         FormatNode(node, strBuilder, "math.cos");
       } else if (symbol is Division) {
         FormatDivision(node, strBuilder);
       } else if (symbol is Exponential) {
+        MathLibCounter++;
         FormatNode(node, strBuilder, "math.exp");
       } else if (symbol is GreaterThan) {
         FormatNode(node, strBuilder, infixSymbol: " > ");
       } else if (symbol is IfThenElse) {
+        EvaluateIfCounter++;
         FormatNode(node, strBuilder, "evaluate_if");
       } else if (symbol is LessThan) {
         FormatNode(node, strBuilder, infixSymbol: " < ");
       } else if (symbol is Logarithm) {
+        MathLibCounter++;
         FormatNode(node, strBuilder, "math.log");
       } else if (symbol is Multiplication) {
@@ -134,14 +147,18 @@
         FormatNode(node, strBuilder, infixSymbol: " ^ ");
       } else if (symbol is Sine) {
+        MathLibCounter++;
         FormatNode(node, strBuilder, "math.sin");
       } else if (symbol is Subtraction) {
         FormatSubtraction(node, strBuilder);
       } else if (symbol is Tangent) {
+        MathLibCounter++;
         FormatNode(node, strBuilder, "math.tan");
       } else if (symbol is HyperbolicTangent) {
+        MathLibCounter++;
         FormatNode(node, strBuilder, "math.tanh");
       } else if (symbol is Square) {
         FormatPower(node, strBuilder, "2");
       } else if (symbol is SquareRoot) {
+        MathLibCounter++;
         FormatNode(node, strBuilder, "math.sqrt");
       } else if (symbol is Cube) {
@@ -150,4 +167,5 @@
         FormatNode(node, strBuilder, closingSymbol: " ** (1. / 3))");
       } else if (symbol is Power) {
+        MathLibCounter++;
         FormatNode(node, strBuilder, "math.pow");
       } else if (symbol is Root) {
@@ -156,4 +174,5 @@
         FormatNode(node, strBuilder, "abs");
       } else if (symbol is AnalyticQuotient) {
+        MathLibCounter++;
         strBuilder.Append("(");
         FormatRecursively(node.GetSubtree(0), strBuilder);
@@ -188,4 +207,5 @@
 
     private void FormatPower(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, string exponent) {
+      MathLibCounter++;
       strBuilder.Append("math.pow(");
       FormatRecursively(node.GetSubtree(0), strBuilder);
@@ -194,4 +214,5 @@
 
     private void FormatRoot(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
+      MathLibCounter++;
       strBuilder.Append("math.pow(");
       FormatRecursively(node.GetSubtree(0), strBuilder);
