Function run_all_benchmarks
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def run_all_benchmarks(method='forward', order=4, x_values=(0.1, 0.5, 1.0, 5), n_max=11,
show_plot=True):
epsilon = MinStepGenerator(base_step=None, scale=None, step_nom=None, num_extrap=0)
- Read upRead up
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
Consider using '{n
: n, order
: order, method
: method, fun
: name, error
: np.nan, ... }' instead of a call to 'dict'. Open
return dict(n=n, order=order, method=method, fun=name,
- Read upRead up
- Exclude checks
Emitted when using dict() to create a dictionary instead of a literal '{ ... }'. The literal is faster as it avoids an additional function call.
Consider using '{n
: n, order
: order, method
: method, fun
: name, error
: error, ... }' instead of a call to 'dict'. Open
return dict(n=n, order=order, method=method, fun=name,
- Read upRead up
- Exclude checks
Emitted when using dict() to create a dictionary instead of a literal '{ ... }'. The literal is faster as it avoids an additional function call.
Too many arguments (6/5) Open
def benchmark(x=0.0001, dfun=None, fd=None, name='', scales=None, show_plot=True):
- Read upRead up
- Exclude checks
Used when a function or method takes too many arguments.
Consider using '{n
: n, order
: order, method
: method, fun
: name, error
: np.nan, ... }' instead of a call to 'dict'. Open
return dict(n=n, order=order, method=method, fun=name,
- Read upRead up
- Exclude checks
Emitted when using dict() to create a dictionary instead of a literal '{ ... }'. The literal is faster as it avoids an additional function call.
Too many local variables (16/15) Open
def run_all_benchmarks(method='forward', order=4, x_values=(0.1, 0.5, 1.0, 5), n_max=11,
- Read upRead up
- Exclude checks
Used when a function or method has too many local variables.
Unable to import 'numpy' Open
import numpy as np
- Read upRead up
- Exclude checks
Used when pylint has been unable to import a module.
Unable to import 'matplotlib.pyplot' Open
import matplotlib.pyplot as plt
- Read upRead up
- Exclude checks
Used when pylint has been unable to import a module.
Unused MaxStepGenerator imported from numdifftools.step_generators Open
from numdifftools.step_generators import default_scale, MinStepGenerator, MaxStepGenerator
- Read upRead up
- Exclude checks
Used when an imported module or variable is not used.
Catching too general exception Exception Open
except Exception:
- Read upRead up
- Exclude checks
If you use a naked except Exception:
clause, you might end up catching exceptions other than the ones you expect to catch. This can hide bugs or make it harder to debug programs when unrelated errors are hidden.
Formatting a regular string which could be a f-string Open
header = 'method="{}", order={}, x_values={}:'.format(method, order, str(x_values))
- Read upRead up
- Exclude checks
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
.
Argument name fd
doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern) Open
def benchmark(x=0.0001, dfun=None, fd=None, name='', scales=None, show_plot=True):
- Read upRead up
- Exclude checks
Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).
third party import import numpy as np
should be placed before from numdifftools.example_functions import get_function, function_names
Open
import numpy as np
- Read upRead up
- Exclude checks
Used when PEP8 import order is not respected (standard imports first, then third-party libraries, then local imports).
third party import import matplotlib.pyplot as plt
should be placed before from numdifftools.example_functions import get_function, function_names
Open
import matplotlib.pyplot as plt
- Read upRead up
- Exclude checks
Used when PEP8 import order is not respected (standard imports first, then third-party libraries, then local imports).
Variable name tt
doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern) Open
tt = dfun(x)
- Read upRead up
- Exclude checks
Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).
Missing function or method docstring Open
def benchmark(x=0.0001, dfun=None, fd=None, name='', scales=None, show_plot=True):
- Read upRead up
- Exclude checks
Used when a function or method has no docstring. Some special methods like init do not require a docstring.
Argument name fd
doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern) Open
def _compute_relative_errors(x, dfun, fd, scales):
- Read upRead up
- Exclude checks
Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).
Formatting a regular string which could be a f-string Open
"7th"] + ["%d'th" % i for i in range(8, 25)]
- Read upRead up
- Exclude checks
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
.
Variable name fd
doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern) Open
fd = Derivative(fun0, step=epsilon, method=method, n=n, order=order)
- Read upRead up
- Exclude checks
Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).
Formatting a regular string which could be a f-string Open
title = "The %s derivative using %s, order=%d" % (txt[n], method, order)
- Read upRead up
- Exclude checks
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
print('n={}, scale={:.2f}'.format(n, default_scale(method, n, order)))
- Read upRead up
- Exclude checks
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
print('n={}, mean scale={:.2f}, median scale={:.2f}'.format(n,
- Read upRead up
- Exclude checks
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
.
Missing function or method docstring Open
def run_all_benchmarks(method='forward', order=4, x_values=(0.1, 0.5, 1.0, 5), n_max=11,
- Read upRead up
- Exclude checks
Used when a function or method has no docstring. Some special methods like init do not require a docstring.
Formatting a regular string which could be a f-string Open
error = float('{:.3g}'.format(relativ_errors[i]))
- Read upRead up
- Exclude checks
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
.
Missing function or method docstring Open
def plot_error(scales, relativ_error, scale0, title='', label=''):
- Read upRead up
- Exclude checks
Used when a function or method has no docstring. Some special methods like init do not require a docstring.