LiberTEM/LiberTEM

View on GitHub
src/libertem/common/buffers.py

Summary

Maintainability
D
1 day
Test Coverage

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

            assert roi_part.shape[0] == partition.shape[0]
Severity: Info
Found in src/libertem/common/buffers.py by bandit

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

        assert self._data_coords_global
Severity: Info
Found in src/libertem/common/buffers.py by bandit

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

        assert result.shape == shape
Severity: Info
Found in src/libertem/common/buffers.py by bandit

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

        assert not buf._data_coords_global
Severity: Info
Found in src/libertem/common/buffers.py by bandit

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

            assert result_start < len(self._data)
Severity: Info
Found in src/libertem/common/buffers.py by bandit

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

        assert self._data is None
Severity: Info
Found in src/libertem/common/buffers.py by bandit

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

        assert buf.dtype == self._dtype
Severity: Info
Found in src/libertem/common/buffers.py by bandit

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

        assert prod(new_data.shape) > 0
Severity: Info
Found in src/libertem/common/buffers.py by bandit

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

            assert roi_count <= partition.shape[0]
Severity: Info
Found in src/libertem/common/buffers.py by bandit

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

            assert result_stop <= len(self._data)
Severity: Info
Found in src/libertem/common/buffers.py by bandit

File buffers.py has 555 lines of code (exceeds 400 allowed). Consider refactoring.
Open

from typing import Any, Iterable, Optional, Tuple, Union, TYPE_CHECKING
from typing_extensions import Literal
import mmap
import math
import functools
Severity: Major
Found in src/libertem/common/buffers.py - About 5 hrs to fix

    BufferWrapper has 32 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class BufferWrapper:
        """
        Helper class to automatically allocate buffers, either for partitions or
        the whole dataset, and create views for partitions or single frames.
    
    
    Severity: Minor
    Found in src/libertem/common/buffers.py - About 4 hrs to fix

      Cyclomatic complexity is too high in method get_view_for_tile. (9)
      Open

          def get_view_for_tile(self, partition, tile):
              """
              get a view for a single tile in a partition-sized buffer
              (partition-sized here means the reduced result for a whole partition,
              not the partition itself!)
      Severity: Minor
      Found in src/libertem/common/buffers.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 get_view_for_frame. (8)
      Open

          def get_view_for_frame(self, partition, tile, frame_idx):
              """
              get a view for a single frame in a partition- or dataset-sized buffer
              (partition-sized here means the reduced result for a whole partition,
              not the partition itself!)
      Severity: Minor
      Found in src/libertem/common/buffers.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 data. (7)
      Open

          @property
          def data(self):
              """
              Get the buffer contents in shape that corresponds to the
              original dataset shape. If a ROI is set, embed the result into a new
      Severity: Minor
      Found in src/libertem/common/buffers.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 _shape_for_kind. (6)
      Open

          def _shape_for_kind(self, kind, orig_shape, roi_count=None):
              if self._kind == "nav":
                  if roi_count is None:
                      nav_shape = tuple(orig_shape.nav)
                  else:
      Severity: Minor
      Found in src/libertem/common/buffers.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 get_view_for_frame has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_view_for_frame(self, partition, tile, frame_idx):
              """
              get a view for a single frame in a partition- or dataset-sized buffer
              (partition-sized here means the reduced result for a whole partition,
              not the partition itself!)
      Severity: Minor
      Found in src/libertem/common/buffers.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 _shape_for_kind has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _shape_for_kind(self, kind, orig_shape, roi_count=None):
              if self._kind == "nav":
                  if roi_count is None:
                      nav_shape = tuple(orig_shape.nav)
                  else:
      Severity: Minor
      Found in src/libertem/common/buffers.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 get_view_for_tile has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_view_for_tile(self, partition, tile):
              """
              get a view for a single tile in a partition-sized buffer
              (partition-sized here means the reduced result for a whole partition,
              not the partition itself!)
      Severity: Minor
      Found in src/libertem/common/buffers.py - About 45 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 get_contiguous_view_for_tile has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_contiguous_view_for_tile(self, partition, tile):
              '''
              Make a cached contiguous copy of the view for a single tile
              if necessary.
      
      
      Severity: Minor
      Found in src/libertem/common/buffers.py - About 45 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 flush has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def flush(self, debug=False):
              '''
              Write back any cached contiguous copies
      
              .. versionadded:: 0.5.0
      Severity: Minor
      Found in src/libertem/common/buffers.py - About 25 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 data has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def data(self):
              """
              Get the buffer contents in shape that corresponds to the
              original dataset shape. If a ROI is set, embed the result into a new
              array; unset values have NaN value for floating point types,
      Severity: Minor
      Found in src/libertem/common/buffers.py - About 25 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

      There are no issues that match your filters.

      Category
      Status