adam2392/eegio

View on GitHub
eegio/base/utils/data_structures_utils.py

Summary

Maintainability
F
5 days
Test Coverage

File data_structures_utils.py has 660 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Data structure manipulations and conversions
import contextlib
import io
import json
import ntpath
Severity: Major
Found in eegio/base/utils/data_structures_utils.py - About 1 day to fix

    Function assert_arrays has a Cognitive Complexity of 56 (exceeds 5 allowed). Consider refactoring.
    Open

    def assert_arrays(params, shape=None, transpose=False):
        # type: (object, object) -> object
        if shape is None or not (
            isinstance(shape, tuple)
            and len(shape) in range(3)
    Severity: Minor
    Found in eegio/base/utils/data_structures_utils.py - About 1 day 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 assert_equal_objects has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
    Open

    def assert_equal_objects(obj1, obj2, attributes_dict=None, logger=None):
        def print_not_equal_message(attr, field1, field2, logger):
            # logger.error("\n\nValueError: Original and read object field "+ attr + " not equal!")
            # raise_value_error("\n\nOriginal and read object field " + attr + " not equal!")
            logger.warning(
    Severity: Minor
    Found in eegio/base/utils/data_structures_utils.py - About 6 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

    Function copy_object_attributes has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def copy_object_attributes(
        obj1, obj2, attr1, attr2=None, deep_copy=False, check_none=False
    ):
        attr1 = ensure_list(attr1)
        if attr2 is None:
    Severity: Minor
    Found in eegio/base/utils/data_structures_utils.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 obj_to_dict has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def obj_to_dict(obj):
        """
        :param obj: Python object to introspect
        :return: dictionary after recursively taking obj fields and their values
        """
    Severity: Minor
    Found in eegio/base/utils/data_structures_utils.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 copy_object_attributes has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def copy_object_attributes(
    Severity: Minor
    Found in eegio/base/utils/data_structures_utils.py - About 45 mins to fix

      Function findtimewins has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      def findtimewins(times, timepoints):
          indices = []
          for time in ensure_list(times):
              if time == 0:
                  indices.append(time)
      Severity: Minor
      Found in eegio/base/utils/data_structures_utils.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 formal_repr has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      def formal_repr(instance, attr_dict, sort_dict_flag=False):
          """ A formal string representation for an object.
          :param attr_dict: dictionary attribute_name: attribute_value
          :param instance:  Instance to read class name from it
          """
      Severity: Minor
      Found in eegio/base/utils/data_structures_utils.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

      Consider simplifying this complex logical expression.
      Open

                  if (
                      isinstance(field1, str)
                      or isinstance(field1, list)
                      or isinstance(field1, dict)
                      or (isinstance(field1, np.ndarray) and field1.dtype.kind in "OSU")
      Severity: Major
      Found in eegio/base/utils/data_structures_utils.py - About 40 mins to fix

        Consider simplifying this complex logical expression.
        Open

                if (transpose is "horizontal" or "row" and shape[0] > shape[1]) or (
                    transpose is "vertical" or "column" and shape[0] < shape[1]
                ):
                    shape = list(shape)
                    temp = shape[1]
        Severity: Major
        Found in eegio/base/utils/data_structures_utils.py - About 40 mins to fix

          Function merge_metadata has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

          def merge_metadata(metadata1, metadata2, overwrite=False):
              for key in metadata1.keys():
                  if overwrite is False:
                      if key not in metadata2.keys():
                          metadata2[key] = metadata1[key]
          Severity: Minor
          Found in eegio/base/utils/data_structures_utils.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

          Avoid too many return statements within this function.
          Open

              return ret
          Severity: Major
          Found in eegio/base/utils/data_structures_utils.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return json.JSONEncoder.default(self, obj)
            Severity: Major
            Found in eegio/base/utils/data_structures_utils.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return ret
              Severity: Major
              Found in eegio/base/utils/data_structures_utils.py - About 30 mins to fix

                Function ensure_list has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                def ensure_list(arg):
                    if not (isinstance(arg, list)):
                        try:  # if iterable
                            if isinstance(arg, (str, dict)):
                                arg = [arg]
                Severity: Minor
                Found in eegio/base/utils/data_structures_utils.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 list_of_dicts_to_dicts_of_ndarrays has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                def list_of_dicts_to_dicts_of_ndarrays(lst, shape=None):
                    d = dict(zip(lst[0], zip(*list([d.values() for d in lst]))))
                    if isinstance(shape, tuple):
                        for key, val in d.items():
                            d[key] = np.reshape(np.stack(d[key]), shape)
                Severity: Minor
                Found in eegio/base/utils/data_structures_utils.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

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

                def ensure_string(arg):
                    if not (isinstance(arg, str)):
                        if arg is None:
                            return ""
                        else:
                Severity: Major
                Found in eegio/base/utils/data_structures_utils.py and 1 other location - About 2 hrs to fix
                eegio/base/utils/data_structures_utils.py on lines 557..564

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

                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

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

                def ensure_string(arg):
                    if not (isinstance(arg, str)):
                        if arg is None:
                            return ""
                        else:
                Severity: Major
                Found in eegio/base/utils/data_structures_utils.py and 1 other location - About 2 hrs to fix
                eegio/base/utils/data_structures_utils.py on lines 535..542

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

                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

                    timepoints = np.append(timestarts[:, np.newaxis], timeends[:, np.newaxis], axis=1)
                Severity: Major
                Found in eegio/base/utils/data_structures_utils.py and 1 other location - About 1 hr to fix
                eegio/base/utils/data_structures_utils.py on lines 177..178

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

                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

                    samplepoints = np.append(
                        samplestarts[:, np.newaxis], sampleends[:, np.newaxis], axis=1
                Severity: Major
                Found in eegio/base/utils/data_structures_utils.py and 1 other location - About 1 hr to fix
                eegio/base/utils/data_structures_utils.py on lines 245..245

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

                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

                        if isinstance(val, dict):
                            formal += "\n" + key + "=["
                            for key2, val2 in val.items():
                                formal += "\n" + str(key2) + " = " + str(val2)
                            formal += "]"
                Severity: Minor
                Found in eegio/base/utils/data_structures_utils.py and 1 other location - About 35 mins to fix
                eegio/base/utils/data_structures_utils.py on lines 452..453

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

                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

                            for key2, val2 in val.items():
                                formal += "\n" + str(key2) + " = " + str(val2)
                Severity: Minor
                Found in eegio/base/utils/data_structures_utils.py and 1 other location - About 35 mins to fix
                eegio/base/utils/data_structures_utils.py on lines 450..456

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

                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

                There are no issues that match your filters.

                Category
                Status