chrislit/abydos

View on GitHub
abydos/stats/_confusion_table.py

Summary

Maintainability
F
5 days
Test Coverage

File _confusion_table.py has 1528 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2014-2020 by Christopher C. Little.
# This file is part of Abydos.
#
# Abydos is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Severity: Major
Found in abydos/stats/_confusion_table.py - About 4 days to fix

    ConfusionTable has 69 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ConfusionTable:
        """ConfusionTable object.
    
        This object is initialized by passing either four integers (or a tuple of
        four integers) representing the squares of a confusion table:
    Severity: Major
    Found in abydos/stats/_confusion_table.py - About 1 day to fix

      Cyclomatic complexity is too high in method __eq__. (17)
      Open

          def __eq__(self, other: object) -> bool:
              """Perform eqality (==) comparison.
      
              Compares a ConfusionTable to another ConfusionTable or its equivalent
              in the form of a tuple, list, or dict.
      Severity: Minor
      Found in abydos/stats/_confusion_table.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

      Cyclomatic complexity is too high in method __init__. (8)
      Open

          def __init__(
              self,
              tp: Union[
                  float,
                  Tuple[float, float, float, float],
      Severity: Minor
      Found in abydos/stats/_confusion_table.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 __init__ has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def __init__(
              self,
              tp: Union[
                  float,
                  Tuple[float, float, float, float],
      Severity: Minor
      Found in abydos/stats/_confusion_table.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

      Function __eq__ has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def __eq__(self, other: object) -> bool:
              """Perform eqality (==) comparison.
      
              Compares a ConfusionTable to another ConfusionTable or its equivalent
              in the form of a tuple, list, or dict.
      Severity: Minor
      Found in abydos/stats/_confusion_table.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

      Avoid too many return statements within this function.
      Open

              return False
      Severity: Major
      Found in abydos/stats/_confusion_table.py - About 30 mins to fix

        Unnecessary elif after return
        Open

                if not precision or not recall:
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        Used in order to highlight an unnecessary block of code following an if containing a return statement. As such, it will warn when it encounters an else following a chain of ifs, all of them containing a return statement.

        Too many public methods (65/20)
        Open

        class ConfusionTable:
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

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

        Remove those useless parentheses.
        Open

                            for _ in (

        The use of parentheses, even those not required to enforce a desired order of operations, can clarify the intent behind a piece of code. But redundant pairs of parentheses could be misleading, and should be removed.

        Noncompliant Code Example

        return ((3))        # Noncompliant
        return ((x + 1))    # Noncompliant
        x = ((y / 2)) + 1   # Noncompliant
        

        Compliant Solution

        return 3
        return (3)
        return x + 1
        return (x + 1)
        x = y / 2 + 1
        x = (y / 2) + 1
        

        Merge this if statement with the enclosing one.
        Open

                    if (

        Merging collapsible if statements increases the code's readability.

        Noncompliant Code Example

        if condition1:
            if condition2:
                # ...
        

        Compliant Solution

        if condition1 and condition2:
            # ...
        

        Wrong hanging indentation before block (add 4 spaces).
        Open

                        self._tp == other.true_pos()
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO self.tp == other.truepos() ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                        and self._fn == other[3]
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO and self._fn == other[3] ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                        self._tp == other['tp']
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO self._tp == other['tp'] ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                        and self._fp == other.false_pos()
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO and self.fp == other.falsepos() ^ |

        Too many lines in module (2176/1000)
        Open

        # Copyright 2014-2020 by Christopher C. Little.
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        Used when a module has too many lines, reducing its readability.

        Wrong hanging indentation before block (add 4 spaces).
        Open

                tp: Union[
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO tp: Union[ ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                        and self._tn == other['tn']
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO and self._tn == other['tn'] ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                        and self._fn == other['fn']
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO and self._fn == other['fn'] ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                fp: float = 0.0,
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO fp: float = 0.0, ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                tn: float = 0.0,
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO tn: float = 0.0, ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                        and self._fp == other['fp']
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO and self._fp == other['fp'] ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                self,
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO self, ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                        and self._fn == other.false_neg()
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO and self.fn == other.falseneg() ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                        and self._fp == other[2]
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO and self._fp == other[2] ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                        self._tp == other[0]
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO self._tp == other[0] ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                        and self._tn == other[1]
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO and self._tn == other[1] ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                fn: float = 0.0,
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO fn: float = 0.0, ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                        and self._tn == other.true_neg()
        Severity: Info
        Found in abydos/stats/_confusion_table.py by pylint

        TODO and self.tn == other.trueneg() ^ |

        There are no issues that match your filters.

        Category
        Status