danishi/dynamodb-csv

View on GitHub
app/dynamodb/csv_import.py

Summary

Maintainability
C
1 day
Test Coverage

Function csv_import has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

def csv_import(table: Any, file: str, ignore: bool = False) -> Tuple:
    """csv import into DynamoDB table

    Args:
        table (Any): boto3 DynamoDB table object
Severity: Minor
Found in app/dynamodb/csv_import.py - About 5 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 write_to_dynamo has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

def write_to_dynamo(table: Any, rows: Dict, ignore: bool = False) -> None:
    """csv rows into DynamoDB

    Args:
        table (Any): boto3 DynamoDB table object
Severity: Minor
Found in app/dynamodb/csv_import.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 convert_column has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

def convert_column(spec: str, row: Dict, key: str, delimiter: str) -> Any:
    """convert column

    Args:
        spec (str): type of column
Severity: Minor
Found in app/dynamodb/csv_import.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 deeply nested control flow statements.
Open

                        if "ConvertBlankToDropAttrs" in csv_spec["IMPORT_OPTION"] and not row[key]:
                            to_drop_attrs = csv_spec.get("IMPORT_OPTION", "ConvertBlankToDropAttrs").split(",")
                            if key in to_drop_attrs:
                                del row[key]
                                continue
Severity: Major
Found in app/dynamodb/csv_import.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                            if "ConvertBlankToNullAttrs" in csv_spec["IMPORT_OPTION"] and not row[key]:
                                to_null_attrs = csv_spec.get("IMPORT_OPTION", "ConvertBlankToNullAttrs").split(",")
                                if key in to_null_attrs:
                                    row[key] = None
                                    continue
    Severity: Major
    Found in app/dynamodb/csv_import.py - About 45 mins to fix

      Avoid too many return statements within this function.
      Open

              return json.loads(row[key], parse_float=Decimal)
      Severity: Major
      Found in app/dynamodb/csv_import.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return row[key]
        Severity: Major
        Found in app/dynamodb/csv_import.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return list(map(Decimal, row[key].split(delimiter)))
          Severity: Major
          Found in app/dynamodb/csv_import.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return row[key].split(delimiter)
            Severity: Major
            Found in app/dynamodb/csv_import.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return set(row[key].split(delimiter))
              Severity: Major
              Found in app/dynamodb/csv_import.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return set(list(map(Decimal, row[key].split(delimiter))))
                Severity: Major
                Found in app/dynamodb/csv_import.py - About 30 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status