pbrod/numdifftools

View on GitHub
src/numdifftools/finite_difference.py

Summary

Maintainability
D
2 days
Test Coverage

LogRule has 21 functions (exceeds 20 allowed). Consider refactoring.
Open

class LogRule(object):
    """Log spaced finite difference rule class

    Parameters
    ----------
Severity: Minor
Found in src/numdifftools/finite_difference.py - About 2 hrs to fix

    Too few public methods (0/2)
    Open

    class DifferenceFunctions(object):

    Used when class has too few public methods, so be sure it's really worth it.

    Too few public methods (1/2)
    Open

    class JacobianDifferenceFunctions(object):

    Used when class has too few public methods, so be sure it's really worth it.

    Class 'HessianDifferenceFunctions' inherits from object, can be safely removed from bases in python3
    Open

    class HessianDifferenceFunctions(object):

    Used when a class inherit from object, which under python3 is implicit, hence can be safely removed from bases.

    Consider using '{central: 2, central2: 2, complex: complex_step, multicomplex: 2, ... }' instead of a call to 'dict'.
    Open

            return dict(central=2,

    Emitted when using dict() to create a dictionary instead of a literal '{ ... }'. The literal is faster as it avoids an additional function call.

    Too few public methods (0/2)
    Open

    class HessdiagDifferenceFunctions(object):

    Used when class has too few public methods, so be sure it's really worth it.

    Class 'JacobianDifferenceFunctions' inherits from object, can be safely removed from bases in python3
    Open

    class JacobianDifferenceFunctions(object):

    Used when a class inherit from object, which under python3 is implicit, hence can be safely removed from bases.

    Consider using '{backward: 1, forward: 1}' instead of a call to 'dict'.
    Open

            return dict(backward=1, forward=1).get(self.method, 2)

    Emitted when using dict() to create a dictionary instead of a literal '{ ... }'. The literal is faster as it avoids an additional function call.

    Too few public methods (0/2)
    Open

    class HessianDifferenceFunctions(object):

    Used when class has too few public methods, so be sure it's really worth it.

    Class 'LogRule' inherits from object, can be safely removed from bases in python3
    Open

    class LogRule(object):

    Used when a class inherit from object, which under python3 is implicit, hence can be safely removed from bases.

    Class 'DifferenceFunctions' inherits from object, can be safely removed from bases in python3
    Open

    class DifferenceFunctions(object):

    Used when a class inherit from object, which under python3 is implicit, hence can be safely removed from bases.

    Class 'HessdiagDifferenceFunctions' inherits from object, can be safely removed from bases in python3
    Open

    class HessdiagDifferenceFunctions(object):

    Used when a class inherit from object, which under python3 is implicit, hence can be safely removed from bases.

    Unable to import 'numpy'
    Open

    import numpy as np
    Severity: Critical
    Found in src/numdifftools/finite_difference.py by pylint

    Used when pylint has been unable to import a module.

    Unable to import 'numpy'
    Open

    from numpy import linalg
    Severity: Critical
    Found in src/numdifftools/finite_difference.py by pylint

    Used when pylint has been unable to import a module.

    Unable to import 'scipy'
    Open

    from scipy import special
    Severity: Critical
    Found in src/numdifftools/finite_difference.py by pylint

    Used when pylint has been unable to import a module.

    Number of parameters was 2 in 'LogRule._vstack' and is now 3 in overriding 'LogJacobianRule._vstack' method
    Open

        def _vstack(self, sequence, steps):

    Used when a method has a different number of arguments than in the implemented interface or in an overridden method. Extra arguments with default values are ignored.

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

        @staticmethod
        def _vstack(sequence, steps):
            original_shape = np.shape(sequence[0])
            f_del = np.vstack([np.ravel(r) for r in sequence])
            one = np.ones(original_shape)
    Severity: Major
    Found in src/numdifftools/finite_difference.py and 1 other location - About 7 hrs to fix
    src/numdifftools/limits.py on lines 209..217

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 118.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

            partials = [(f(x + hi) + f(x - hi)) / 2.0 - f_x for hi in increments]
    Severity: Major
    Found in src/numdifftools/finite_difference.py and 1 other location - About 1 hr to fix
    src/numdifftools/finite_difference.py on lines 128..128

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 47.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

            return np.array([(f(x + hi) + f(x - hi)) / 2.0 - f_x for hi in steps])
    Severity: Major
    Found in src/numdifftools/finite_difference.py and 1 other location - About 1 hr to fix
    src/numdifftools/finite_difference.py on lines 195..195

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 47.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

                    hess[i, j] = (f(x + eee[i, :] + eee[j, :]) - g[i] - g[j] + f_x) / hess[j, i]
    Severity: Minor
    Found in src/numdifftools/finite_difference.py and 1 other location - About 45 mins to fix
    src/numdifftools/finite_difference.py on lines 306..306

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 35.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

                f_del = np.vstack([np.atleast_1d(r).transpose(axes).ravel() for r in sequence])
    Severity: Minor
    Found in src/numdifftools/finite_difference.py and 1 other location - About 45 mins to fix
    src/numdifftools/finite_difference.py on lines 684..684

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 35.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

                h = np.vstack([np.atleast_1d(r).transpose(axes).ravel() for r in steps])
    Severity: Minor
    Found in src/numdifftools/finite_difference.py and 1 other location - About 45 mins to fix
    src/numdifftools/finite_difference.py on lines 683..683

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 35.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

                    hess[i, j] = (f(x + eee[i, :] + eee[j, :])
    Severity: Minor
    Found in src/numdifftools/finite_difference.py and 1 other location - About 45 mins to fix
    src/numdifftools/finite_difference.py on lines 327..327

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 35.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

            return np.array([(f(x + hi) - f(x - hi)) / 2.0 for hi in steps])
    Severity: Minor
    Found in src/numdifftools/finite_difference.py and 1 other location - About 35 mins to fix
    src/numdifftools/finite_difference.py on lines 61..61

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 33.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

            return (f(x0i + h) - f(x0i - h)) / 2.0
    Severity: Minor
    Found in src/numdifftools/finite_difference.py and 1 other location - About 35 mins to fix
    src/numdifftools/finite_difference.py on lines 122..122

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 33.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Missing whitespace around arithmetic operator
    Open

            return np.array([(f(x + j_1*ih) + f(x - j_1*ih)).imag for ih in steps])
    Severity: Minor
    Found in src/numdifftools/finite_difference.py by pep8

    Surround operators with a single space on either side.

    - Always surround these binary operators with a single space on
      either side: assignment (=), augmented assignment (+=, -= etc.),
      comparisons (==, <, >, !=, <=, >=, in, not in, is, is not),
      Booleans (and, or, not).
    
    - If operators with different priorities are used, consider adding
      whitespace around the operators with the lowest priorities.
    
    Okay: i = i + 1
    Okay: submitted += 1
    Okay: x = x * 2 - 1
    Okay: hypot2 = x * x + y * y
    Okay: c = (a + b) * (a - b)
    Okay: foo(bar, key='word', *args, **kwargs)
    Okay: alpha[:-i]
    
    E225: i=i+1
    E225: submitted +=1
    E225: x = x /2 - 1
    E225: z = x **y
    E225: z = 1and 1
    E226: c = (a+b) * (a-b)
    E226: hypot2 = x*x + y*y
    E227: c = a|b
    E228: msg = fmt%(errno, errmsg)

    Line break after binary operator
    Open

                    self.method in ['forward', 'backward'] or
    Severity: Minor
    Found in src/numdifftools/finite_difference.py by pep8

    Avoid breaks after binary operators.

    The preferred place to break around a binary operator is before the
    operator, not after it.
    
    W504: (width == 0 +\n height == 0)
    W504: (width == 0 and\n height == 0)
    W504: var = (1 &\n       ~2)
    
    Okay: foo(\n    -x)
    Okay: foo(x\n    [])
    Okay: x = '''\n''' + ''
    Okay: x = '' + '''\n'''
    Okay: foo(x,\n    -y)
    Okay: foo(x,  # comment\n    -y)
    
    The following should be W504 but unary_context is tricky with these
    Okay: var = (1 /\n       -2)
    Okay: var = (1 +\n       -1 +\n       -2)

    Line break after binary operator
    Open

                    self._complex_high_order and
    Severity: Minor
    Found in src/numdifftools/finite_difference.py by pep8

    Avoid breaks after binary operators.

    The preferred place to break around a binary operator is before the
    operator, not after it.
    
    W504: (width == 0 +\n height == 0)
    W504: (width == 0 and\n height == 0)
    W504: var = (1 &\n       ~2)
    
    Okay: foo(\n    -x)
    Okay: foo(x\n    [])
    Okay: x = '''\n''' + ''
    Okay: x = '' + '''\n'''
    Okay: foo(x,\n    -y)
    Okay: foo(x,  # comment\n    -y)
    
    The following should be W504 but unary_context is tricky with these
    Okay: var = (1 /\n       -2)
    Okay: var = (1 +\n       -1 +\n       -2)

    Missing whitespace around arithmetic operator
    Open

            return np.array([(f(x + j_1*ih) + f(x - j_1*ih)).imag for ih in steps])
    Severity: Minor
    Found in src/numdifftools/finite_difference.py by pep8

    Surround operators with a single space on either side.

    - Always surround these binary operators with a single space on
      either side: assignment (=), augmented assignment (+=, -= etc.),
      comparisons (==, <, >, !=, <=, >=, in, not in, is, is not),
      Booleans (and, or, not).
    
    - If operators with different priorities are used, consider adding
      whitespace around the operators with the lowest priorities.
    
    Okay: i = i + 1
    Okay: submitted += 1
    Okay: x = x * 2 - 1
    Okay: hypot2 = x * x + y * y
    Okay: c = (a + b) * (a - b)
    Okay: foo(bar, key='word', *args, **kwargs)
    Okay: alpha[:-i]
    
    E225: i=i+1
    E225: submitted +=1
    E225: x = x /2 - 1
    E225: z = x **y
    E225: z = 1and 1
    E226: c = (a+b) * (a-b)
    E226: hypot2 = x*x + y*y
    E227: c = a|b
    E228: msg = fmt%(errno, errmsg)

    Line break after binary operator
    Open

            return ((even_derivative and self.method in ('central', 'central2')) or
    Severity: Minor
    Found in src/numdifftools/finite_difference.py by pep8

    Avoid breaks after binary operators.

    The preferred place to break around a binary operator is before the
    operator, not after it.
    
    W504: (width == 0 +\n height == 0)
    W504: (width == 0 and\n height == 0)
    W504: var = (1 &\n       ~2)
    
    Okay: foo(\n    -x)
    Okay: foo(x\n    [])
    Okay: x = '''\n''' + ''
    Okay: x = '' + '''\n'''
    Okay: foo(x,\n    -y)
    Okay: foo(x,  # comment\n    -y)
    
    The following should be W504 but unary_context is tricky with these
    Okay: var = (1 /\n       -2)
    Okay: var = (1 +\n       -1 +\n       -2)

    Line break after binary operator
    Open

            if (self.method == 'complex' and self._derivative_mod_four_is_zero or
    Severity: Minor
    Found in src/numdifftools/finite_difference.py by pep8

    Avoid breaks after binary operators.

    The preferred place to break around a binary operator is before the
    operator, not after it.
    
    W504: (width == 0 +\n height == 0)
    W504: (width == 0 and\n height == 0)
    W504: var = (1 &\n       ~2)
    
    Okay: foo(\n    -x)
    Okay: foo(x\n    [])
    Okay: x = '''\n''' + ''
    Okay: x = '' + '''\n'''
    Okay: foo(x,\n    -y)
    Okay: foo(x,  # comment\n    -y)
    
    The following should be W504 but unary_context is tricky with these
    Okay: var = (1 /\n       -2)
    Okay: var = (1 +\n       -1 +\n       -2)

    Formatting a regular string which could be a f-string
    Open

                    'Parity must be 0, 1, 2, 3, 4, 5 or 6! ({0:d})'.format(parity))

    Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

    Formatting a regular string which could be a f-string
    Open

            _assert(n_r < num_steps, 'num_steps ({0:d}) must  be larger than '

    Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

    Formatting a regular string which could be a f-string
    Open

            first = '_{0!s}'.format(self.method)

    Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

    There are no issues that match your filters.

    Category
    Status