pygae/galgebra

View on GitHub
galgebra/dop.py

Summary

Maintainability
C
1 day
Test Coverage

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

        assert not isinstance(other, Pdop)
Severity: Info
Found in galgebra/dop.py by bandit

File dop.py has 304 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Differential operators, for all sympy expressions

For multivector-customized differential operators, see :class:`galgebra.mv.Dop`.
"""
Severity: Minor
Found in galgebra/dop.py - About 3 hrs to fix

    Function _latex has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def _latex(self, print_obj):
            if len(self.terms) == 0:
                return ZERO_STR
    
            self = self._with_sorted_terms()
    Severity: Minor
    Found in galgebra/dop.py - About 2 hrs 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

    Cyclomatic complexity is too high in function _merge_terms. (9)
    Open

    def _merge_terms(terms1, terms2):
        """ Concatenate and consolidate two sets of already-consolidated terms """
        pdiffs1 = [pdiff for _, pdiff in terms1]
        pdiffs2 = [pdiff for _, pdiff in terms2]
    
    
    Severity: Minor
    Found in galgebra/dop.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

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

    class Sdop(_BaseDop):
        """
        Scalar differential operator is of the form (Einstein summation)
    
        .. math:: D = c_{i}*D_{i}
    Severity: Minor
    Found in galgebra/dop.py - About 2 hrs to fix

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

          def _latex(self, print_obj):
              if len(self.terms) == 0:
                  return ZERO_STR
      
              self = self._with_sorted_terms()
      Severity: Minor
      Found in galgebra/dop.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 _sympystr. (6)
      Open

          def _sympystr(self, print_obj):
              if len(self.terms) == 0:
                  return ZERO_STR
      
              self = self._with_sorted_terms()
      Severity: Minor
      Found in galgebra/dop.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 _sympystr has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _sympystr(self, print_obj):
              if len(self.terms) == 0:
                  return ZERO_STR
      
              self = self._with_sorted_terms()
      Severity: Minor
      Found in galgebra/dop.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 _eval_derivative_n_times_terms has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def _eval_derivative_n_times_terms(terms, x, n):
          for i in range(n):
              new_terms = []
              for k, term in enumerate(terms):
                  dc = _basic_diff(term[0], x)
      Severity: Minor
      Found in galgebra/dop.py - About 55 mins 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 Add has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def Add(sdop1, sdop2):
              if isinstance(sdop1, Sdop) and isinstance(sdop2, Sdop):
                  return Sdop(_merge_terms(sdop1.terms, sdop2.terms))
              else:
                  # convert values to multiplicative operators
      Severity: Minor
      Found in galgebra/dop.py - About 35 mins 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 _consolidate_terms has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def _consolidate_terms(terms):
          """
          Remove zero coefs and consolidate coefs with repeated pdiffs.
          """
          new_coefs = []
      Severity: Minor
      Found in galgebra/dop.py - About 35 mins 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 __init__ has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def __init__(self, *args):
              if len(args) == 1:
                  if isinstance(args[0], Symbol):
                      self.__init_from_symbol(*args)
                  elif isinstance(args[0], (list, tuple)):
      Severity: Minor
      Found in galgebra/dop.py - About 35 mins 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

      Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.
      Open

          def _latex(self, print_obj):
      Severity: Critical
      Found in galgebra/dop.py by sonar-python

      Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

      See

      Remove this commented out code.
      Open

                  # print 'D0, term, dc, pd =', D0, term, dc, pd
      Severity: Major
      Found in galgebra/dop.py by sonar-python

      Programmers should not comment out code as it bloats programs and reduces readability.

      Unused code should be deleted and can be retrieved from source control history if required.

      See

      • MISRA C:2004, 2.4 - Sections of code should not be "commented out".
      • MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
      • MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
      • MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"

      Line too long (80 > 79 characters)
      Open

      For multivector-customized differential operators, see :class:`galgebra.mv.Dop`.
      Severity: Minor
      Found in galgebra/dop.py by pep8

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Line too long (90 > 79 characters)
      Open

          def __init_from_coef_and_pdiffs(self, coefs: List[Any], pdiffs: List['Pdop']) -> None:
      Severity: Minor
      Found in galgebra/dop.py by pep8

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Line too long (86 > 79 characters)
      Open

          """ Base class for differential operators - used to avoid accidental promotion """
      Severity: Minor
      Found in galgebra/dop.py by pep8

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Line too long (99 > 79 characters)
      Open

                  raise ValueError('In Sdop.__init__ coefficent list and Pdop list must be same length.')
      Severity: Minor
      Found in galgebra/dop.py by pep8

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Too many leading '#' for block comment
      Open

      #################### Partial Derivative Operator Class #################
      Severity: Minor
      Found in galgebra/dop.py by pep8

      Separate inline comments by at least two spaces.

      An inline comment is a comment on the same line as a statement.
      Inline comments should be separated by at least two spaces from the
      statement. They should start with a # and a single space.
      
      Each line of a block comment starts with a # and a single space
      (unless it is indented text inside the comment).
      
      Okay: x = x + 1  # Increment x
      Okay: x = x + 1    # Increment x
      Okay: # Block comment
      E261: x = x + 1 # Increment x
      E262: x = x + 1  #Increment x
      E262: x = x + 1  #  Increment x
      E265: #Block comment
      E266: ### Block comment

      Line too long (82 > 79 characters)
      Open

          return [(coef, pdiff) for coef, pdiff in zip(coefs, pdiffs) if coef != S.Zero]
      Severity: Minor
      Found in galgebra/dop.py by pep8

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Line too long (80 > 79 characters)
      Open

              # Ensure that we return the right type even when there are no terms - we
      Severity: Minor
      Found in galgebra/dop.py by pep8

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Line too long (87 > 79 characters)
      Open

              raise ValueError('In_basic_diff type(arg) = ' + str(type(f)) + ' not allowed.')
      Severity: Minor
      Found in galgebra/dop.py by pep8

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Line too long (88 > 79 characters)
      Open

              elif isinstance(__arg, Symbol):  # First order derivative with respect to symbol
      Severity: Minor
      Found in galgebra/dop.py by pep8

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Line too long (80 > 79 characters)
      Open

              # do this by adding `0 * d(arg)/d(nonexistant)`, which must be zero, but
      Severity: Minor
      Found in galgebra/dop.py by pep8

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Too many leading '#' for block comment
      Open

      ################ Scalar Partial Differential Operator Class ############
      Severity: Minor
      Found in galgebra/dop.py by pep8

      Separate inline comments by at least two spaces.

      An inline comment is a comment on the same line as a statement.
      Inline comments should be separated by at least two spaces from the
      statement. They should start with a # and a single space.
      
      Each line of a block comment starts with a # and a single space
      (unless it is indented text inside the comment).
      
      Okay: x = x + 1  # Increment x
      Okay: x = x + 1    # Increment x
      Okay: # Block comment
      E261: x = x + 1 # Increment x
      E262: x = x + 1  #Increment x
      E262: x = x + 1  #  Increment x
      E265: #Block comment
      E266: ### Block comment

      Line too long (89 > 79 characters)
      Open

                  raise TypeError('A dictionary or symbol is required, got {!r}'.format(__arg))
      Severity: Minor
      Found in galgebra/dop.py by pep8

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      There are no issues that match your filters.

      Category
      Status