Repository: fitbenchmarking/fitbenchmarking

Issue:
Fix liniting in Jacobians
Fix the jacobians subdirectory - related to #702

Bring the errors and warnings down to zero, and address others if appropriate.

Discussion:

Patch:
diff --git a/fitbenchmarking/jacobian/analytic_jacobian.py b/fitbenchmarking/jacobian/analytic_jacobian.py
index fff72575..f2a62312 100644
--- a/fitbenchmarking/jacobian/analytic_jacobian.py
+++ b/fitbenchmarking/jacobian/analytic_jacobian.py
@@ -1,11 +1,11 @@
 """
 Module which acts as a analytic Jacobian calculator
 """
+from numpy import matmul
+
 from fitbenchmarking.jacobian.base_jacobian import Jacobian
 from fitbenchmarking.utils.exceptions import NoJacobianError
 
-from numpy import matmul
-
 
 # pylint: disable=useless-super-delegation
 class Analytic(Jacobian):
@@ -14,7 +14,7 @@ class Analytic(Jacobian):
     """
 
     def __init__(self, cost_func):
-        super(Analytic, self).__init__(cost_func)
+        super().__init__(cost_func)
         if not callable(self.problem.jacobian):
             raise NoJacobianError("Problem set selected does not currently "
                                   "support analytic Jacobians")
diff --git a/fitbenchmarking/jacobian/default_jacobian.py b/fitbenchmarking/jacobian/default_jacobian.py
index cff63bee..9f328046 100644
--- a/fitbenchmarking/jacobian/default_jacobian.py
+++ b/fitbenchmarking/jacobian/default_jacobian.py
@@ -5,11 +5,23 @@ from fitbenchmarking.jacobian.base_jacobian import Jacobian
 
 
 # pylint: disable=useless-super-delegation
-class default(Jacobian):
+class Default(Jacobian):
     """
     Use the minimizer's jacobian/derivative approximation
     """
 
     def __init__(self, cost_func):
-        super(default, self).__init__(cost_func)
+        super().__init__(cost_func)
         self.use_default_jac = True
+
+    def eval(self, params, **kwargs):
+        """
+        This should not be called?
+        """
+        raise NotImplementedError
+
+    def eval_cost(self, params, **kwargs):
+        """
+        This should not be called?
+        """
+        raise NotImplementedError
diff --git a/fitbenchmarking/jacobian/jacobian_factory.py b/fitbenchmarking/jacobian/jacobian_factory.py
index c7022056..fd0f75be 100644
--- a/fitbenchmarking/jacobian/jacobian_factory.py
+++ b/fitbenchmarking/jacobian/jacobian_factory.py
@@ -7,7 +7,7 @@ from importlib import import_module
 from inspect import getmembers, isabstract, isclass
 
 from fitbenchmarking.jacobian.base_jacobian import Jacobian
-from fitbenchmarking.utils.exceptions import NoJacobianError, OptionsError
+from fitbenchmarking.utils.exceptions import NoJacobianError
 
 
 def create_jacobian(jac_method):
@@ -25,9 +25,9 @@ def create_jacobian(jac_method):
 
     try:
         module = import_module('.' + module_name, __package__)
-    except ImportError:
+    except ImportError as e:
         raise NoJacobianError('Could not find Jacobian class with type as '
-                              '{}.'.format(jac_method))
+                              '{}.'.format(jac_method)) from e
 
     classes = getmembers(module, lambda m: (isclass(m)
                                             and not isabstract(m)
diff --git a/fitbenchmarking/jacobian/numdifftools_jacobian.py b/fitbenchmarking/jacobian/numdifftools_jacobian.py
index f0149c3a..21ecf46b 100644
--- a/fitbenchmarking/jacobian/numdifftools_jacobian.py
+++ b/fitbenchmarking/jacobian/numdifftools_jacobian.py
@@ -2,23 +2,16 @@
 Module which calculates numdifftools finite difference approximations
 """
 import numdifftools as nd
-import numpy as np
 
 from fitbenchmarking.jacobian.base_jacobian import Jacobian
 
-# pylint: disable=useless-super-delegation
-class numdifftools(Jacobian):
+
+class Numdifftools(Jacobian):
     """
     Implements numdifftools (https://numdifftools.readthedocs.io/en/latest/)
     finite difference approximations to the derivative
     """
 
-    def __init__(self, cost_func):
-        """
-        initializes the numdifftools jacobian
-        """
-        super(numdifftools, self).__init__(cost_func)
-
     def eval(self, params, **kwargs):
         """
         Evaluates Jacobian of the function
@@ -29,9 +22,9 @@ class numdifftools(Jacobian):
         :return: Approximation of the Jacobian
         :rtype: numpy array
         """
-        
+
         # Use the default numdifftools derivatives
-        # 
+        #
         # Note that once jac_func is set up, it can be called
         # multiple times by giving it params.
         # We tested moving the call to nd.Jacobian into
@@ -56,6 +49,6 @@ class numdifftools(Jacobian):
         # Use the default numdifftools derivatives
         jac_cost = nd.Gradient(self.cost_func.eval_cost,
                                method=self.method)
-        
+
         jac = jac_cost(params)
         return jac
diff --git a/fitbenchmarking/jacobian/scipy_jacobian.py b/fitbenchmarking/jacobian/scipy_jacobian.py
index b05faba8..c670fe81 100644
--- a/fitbenchmarking/jacobian/scipy_jacobian.py
+++ b/fitbenchmarking/jacobian/scipy_jacobian.py
@@ -13,9 +13,6 @@ class Scipy(Jacobian):
     Implements SciPy finite difference approximations to the derivative
     """
 
-    def __init__(self, cost_func):
-        super(Scipy, self).__init__(cost_func)
-
     def eval(self, params, **kwargs):
         """
         Evaluates Jacobian


Test patch:
diff --git a/fitbenchmarking/jacobian/tests/__init__.py b/fitbenchmarking/jacobian/tests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/fitbenchmarking/jacobian/tests/test_jacobian.py b/fitbenchmarking/jacobian/tests/test_jacobian.py
index adc8d775..7f331f24 100644
--- a/fitbenchmarking/jacobian/tests/test_jacobian.py
+++ b/fitbenchmarking/jacobian/tests/test_jacobian.py
@@ -1,18 +1,20 @@
-
+"""
+Unit testing for the jacobian directory.
+"""
 from unittest import TestCase
 
 import numpy as np
 
 from fitbenchmarking.cost_func.nlls_cost_func import NLLSCostFunc
-from fitbenchmarking.parsing.fitting_problem import FittingProblem
-from fitbenchmarking.utils.options import Options
-from fitbenchmarking.utils import exceptions
-from fitbenchmarking.jacobian.base_jacobian import Jacobian
-from fitbenchmarking.jacobian.scipy_jacobian import Scipy
-from fitbenchmarking.jacobian.default_jacobian import default
-from fitbenchmarking.jacobian.numdifftools_jacobian import numdifftools
 from fitbenchmarking.jacobian.analytic_jacobian import Analytic
+from fitbenchmarking.jacobian.base_jacobian import Jacobian
+from fitbenchmarking.jacobian.default_jacobian import Default
 from fitbenchmarking.jacobian.jacobian_factory import create_jacobian
+from fitbenchmarking.jacobian.numdifftools_jacobian import Numdifftools
+from fitbenchmarking.jacobian.scipy_jacobian import Scipy
+from fitbenchmarking.parsing.fitting_problem import FittingProblem
+from fitbenchmarking.utils import exceptions
+from fitbenchmarking.utils.options import Options
 
 
 def f(x, p1, p2):
@@ -99,7 +101,7 @@ class TestJacobianClass(TestCase):
         """
         Test that minimizer default jacobian does what it should
         """
-        jac = default(self.cost_func)
+        jac = Default(self.cost_func)
         self.assertTrue(jac.use_default_jac)
 
     def test_numdifftools_eval(self):
@@ -111,7 +113,7 @@ class TestJacobianClass(TestCase):
                        'backward',
                        'complex',
                        'multicomplex']:
-            jac = numdifftools(self.cost_func)
+            jac = Numdifftools(self.cost_func)
             jac.method = method
             eval_result = jac.eval(params=self.params)
             self.assertTrue(np.isclose(self.actual, eval_result).all())
@@ -147,6 +149,7 @@ class TestJacobianClass(TestCase):
         self.fitting_problem.format = "cutest"
         jac = Analytic(self.cost_func)
         eval_result = jac.eval(params=self.params)
+        #  pylint: disable=unsubscriptable-object
         scaled_actual = self.actual * \
             self.fitting_problem.eval_model(self.params)[:, None] / 2
 
@@ -191,7 +194,8 @@ class TestCachedFuncValues(TestCase):
         self.cost_func = NLLSCostFunc(self.fitting_problem)
         self.jacobian = Jacobian(self.cost_func)
 
-    def func(self, x):
+    @staticmethod
+    def func(x):
         """
         Test function for cached value tests.
 
@@ -289,7 +293,7 @@ class TestDerivCostFunc(TestCase):
                        'backward',
                        'complex',
                        'multicomplex']:
-            jac = numdifftools(self.cost_func)
+            jac = Numdifftools(self.cost_func)
             jac.method = method
             eval_result = jac.eval_cost(params=self.params)
             self.assertTrue(np.isclose(self.actual, eval_result).all())
@@ -305,17 +309,17 @@ class TestDerivCostFunc(TestCase):
         self.assertTrue(np.isclose(self.actual, eval_result).all())
 
 
-class FactoryTests(TestCase):
+class TestFactory(TestCase):
     """
     Tests for the Jacobian factory
     """
+    def setUp(self):
+        self.options = Options()
 
     def test_imports(self):
         """
         Test that the factory returns the correct class for inputs
         """
-        self.options = Options()
-
         valid = ['scipy', 'analytic']
 
         invalid = ['numpy', 'random_jac']
diff --git a/fitbenchmarking/results_processing/tests/test_tables.py b/fitbenchmarking/results_processing/tests/test_tables.py
index 7369f086..38d8f135 100644
--- a/fitbenchmarking/results_processing/tests/test_tables.py
+++ b/fitbenchmarking/results_processing/tests/test_tables.py
@@ -15,7 +15,7 @@ from fitbenchmarking.cost_func.weighted_nlls_cost_func import \
 from fitbenchmarking.results_processing.tables import SORTED_TABLE_NAMES
 from fitbenchmarking.results_processing.tables import generate_table
 from fitbenchmarking.results_processing.tables import create_results_tables
-from fitbenchmarking.jacobian.default_jacobian import default as DefaultJac
+from fitbenchmarking.jacobian.default_jacobian import Default as DefaultJac
 from fitbenchmarking.core.results_output import preproccess_data
 from fitbenchmarking.parsing.fitting_problem import FittingProblem
 from fitbenchmarking.utils.fitbm_result import FittingResult