pbrod/numdifftools

View on GitHub
src/numdifftools/fornberg.py

Summary

Maintainability
A
2 hrs
Test Coverage

Cyclomatic complexity is too high in method _check_convergence. (11)
Open

    def _check_convergence(self, i, z0, r, m, bn):
        if self._direction_changes > 1 or self._degenerate:
            self._num_changes += 1
            if self._num_changes >= 1 + self.num_extrap:
                return True, r
Severity: Minor
Found in src/numdifftools/fornberg.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

Function _check_convergence has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def _check_convergence(self, i, z0, r, m, bn):
        if self._direction_changes > 1 or self._degenerate:
            self._num_changes += 1
            if self._num_changes >= 1 + self.num_extrap:
                return True, r
Severity: Minor
Found in src/numdifftools/fornberg.py - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Too many instance attributes (17/7)
Open

class Taylor(object):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when class has too many instance attributes, try to reduce this to get a simpler (and so easier to use) class.

Too many arguments (6/5)
Open

    def _check_convergence(self, i, z0, r, m, bn):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when a function or method takes too many arguments.

Too few public methods (1/2)
Open

class Taylor(object):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

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

Too many arguments (6/5)
Open

def taylor(fun, z0=0, n=1, r=0.0059, num_extrap=3, step_ratio=1.6, **kwds):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when a function or method takes too many arguments.

Too many arguments (6/5)
Open

    def __init__(self, fun, n=1, r=0.0059, num_extrap=3, step_ratio=1.6, **kwds):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when a function or method takes too many arguments.

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

class Taylor(object):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

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/fornberg.py by pylint

Used when pylint has been unable to import a module.

Unable to import 'scipy.special'
Open

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

Used when pylint has been unable to import a module.

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

    (1, 9): (np.array([3., -32, 168, -672, 0, 672, -168, 32, -3]) / 840.0,
             np.arange(-4, 5)),
Severity: Minor
Found in src/numdifftools/fornberg.py and 1 other location - About 30 mins to fix
src/numdifftools/fornberg.py on lines 23..25

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 32.

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

    (2, 9): (np.array([-9., 128, -1008, 8064, -14350,
                       8064, -1008, 128, -9]) / 5040.0,
             np.arange(-4, 5))}
Severity: Minor
Found in src/numdifftools/fornberg.py and 1 other location - About 30 mins to fix
src/numdifftools/fornberg.py on lines 17..18

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 32.

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

Argument name bn doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

    def _get_m1_m2(self, bn, m):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Variable name m2 doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

        m2 = np.max(np.abs(bnc[m // 2:]))
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Attribute name _m doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

        self._m = m
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Variable name m2 doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

        m1, m2 = self._get_m1_m2(bn, m)
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Variable name m1 doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

            m1, m2 = self._get_m1_m2(bn, m)
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Missing function or method docstring
Open

def richardson_parameter(vals, k):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when a function or method has no docstring. Some special methods like init do not require a docstring.

Argument name bn doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

    def _get_max_m1m2(self, bn, m):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name z0 doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

    def _check_convergence(self, i, z0, r, m, bn):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Variable name rs doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

        rs = []
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name x0 doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

def _fd_weights_all(weights, x, x0, n):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name bs doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

def _extrapolate(bs, rs, m):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name z0 doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

def derivative(fun, z0, n=1, **kwds):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Variable name nk doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

    nk = len(rs)
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Variable name m1 doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

        m1, m2 = self._get_m1_m2(bn, m)
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Variable name m2 doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

            m1, m2 = self._get_m1_m2(bn, m)
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Variable name bn doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

            bn = np.fft.fft(fun(_circle(z0, r, m))) / m
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name bn doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

def _poor_convergence(z, r, f, bn, mvec):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name rs doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

def _extrapolate(bs, rs, m):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Missing module docstring
Open

from __future__ import absolute_import, division
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when a module has no docstring. Empty modules do not require a docstring.

Variable name m1 doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

        m1 = np.max(np.abs(bnc[:m // 2]))
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name x0 doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

def fd_weights(x, x0=0, n=1):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name m2 doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

def _check_fft(m1, m2, check_degenerate=True):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Variable name du doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

    du = np.zeros_like(fx)
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Variable name mm doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

    mm = n // 2 + m
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name rs doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

def _get_best_taylor_coefficients(bs, rs, m, max_m1m2):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name m1 doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

def _check_fft(m1, m2, check_degenerate=True):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name z0 doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

    def __call__(self, z0=0):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name x0 doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

def fd_weights_all(x, x0=0, n=1):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Variable name bs doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

        bs = []
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name fx doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

def fd_derivative(fx, x, n=1, m=2):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name bs doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

def _get_best_taylor_coefficients(bs, rs, m, max_m1m2):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name bn doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

    def _check_convergence(self, i, z0, r, m, bn):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

Argument name z0 doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern)
Open

def taylor(fun, z0=0, n=1, r=0.0059, num_extrap=3, step_ratio=1.6, **kwds):
Severity: Info
Found in src/numdifftools/fornberg.py by pylint

Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

There are no issues that match your filters.

Category
Status