airbnb/caravel

View on GitHub
superset/viz.py

Summary

Maintainability
F
1 wk
Test Coverage

File viz.py has 2219 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
Severity: Major
Found in superset/viz.py - About 6 days to fix

    Function to_series has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
    Open

        def to_series(  # pylint: disable=too-many-branches
            self, df: pd.DataFrame, classed: str = "", title_suffix: str = ""
        ) -> list[dict[str, Any]]:
            cols = []
            for col in df.columns:
    Severity: Minor
    Found in superset/viz.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 get_df_payload has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_df_payload(  # pylint: disable=too-many-statements
            self, query_obj: QueryObjectDict | None = None, **kwargs: Any
        ) -> dict[str, Any]:
            """Handles caching around the df payload retrieval"""
            if not query_obj:
    Severity: Minor
    Found in superset/viz.py - About 4 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 query_obj has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        def query_obj(self) -> QueryObjectDict:
            query_obj = super().query_obj()
            label_col = self.form_data.get("mapbox_label")
    
            if not self.form_data.get("groupby"):
    Severity: Minor
    Found in superset/viz.py - About 3 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

    BaseViz has 25 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class BaseViz:  # pylint: disable=too-many-public-methods
        """All visualizations derive this base class"""
    
        viz_type: str | None = None
        verbose_name = "Base Viz"
    Severity: Minor
    Found in superset/viz.py - About 2 hrs to fix

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

          def get_data(self, df: pd.DataFrame) -> VizData:  # pylint: disable=too-many-locals
              if df.empty:
                  return None
      
              metrics = self.metric_labels
      Severity: Minor
      Found in superset/viz.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

      Function get_data has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_data(self, df: pd.DataFrame) -> VizData:
              if df.empty:
                  return None
      
              # pylint: disable=import-outside-toplevel
      Severity: Minor
      Found in superset/viz.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

      Function get_data has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_data(self, df: pd.DataFrame) -> VizData:
              """
              Transform received data frame into an object of the form:
              {
                  'metric1': [
      Severity: Minor
      Found in superset/viz.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

      Function get_data has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_data(self, df: pd.DataFrame) -> VizData:
              if df.empty:
                  return None
              source, target = get_column_names(self.groupby)
              (value,) = self.metric_labels
      Severity: Minor
      Found in superset/viz.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_data has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_data(self, df: pd.DataFrame) -> VizData:  # pylint: disable=too-many-locals
              if df.empty:
                  return None
      
              form_data = self.form_data
      Severity: Minor
      Found in superset/viz.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_data has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_data(self, df: pd.DataFrame) -> VizData:
              comparison_type = self.form_data.get("comparison_type") or "values"
              df = self.process_data(df)
              if comparison_type == "values":
                  # Filter out series with all NaN
      Severity: Minor
      Found in superset/viz.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_data has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_data(self, df: pd.DataFrame) -> VizData:
              if df.empty:
                  return None
      
              data = super().get_data(df)
      Severity: Minor
      Found in superset/viz.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 query_obj has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def query_obj(self) -> QueryObjectDict:  # pylint: disable=too-many-locals
              """Building a query object"""
              self.process_query_filters()
      
              metrics = self.all_metrics or []
      Severity: Minor
      Found in superset/viz.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 handle_js_int_overflow has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def handle_js_int_overflow(
              data: dict[str, list[dict[str, Any]]],
          ) -> dict[str, list[dict[str, Any]]]:
              for record in data.get("records", {}):
                  for k, v in list(record.items()):
      Severity: Minor
      Found in superset/viz.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 run_extra_queries has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def run_extra_queries(self) -> None:
              time_compare = self.form_data.get("time_compare") or []
              # backwards compatibility
              if not isinstance(time_compare, list):
                  time_compare = [time_compare]
      Severity: Minor
      Found in superset/viz.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 __init__ has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def __init__(
              self,
              datasource: BaseDatasource,
              form_data: dict[str, Any],
              force: bool = False,
      Severity: Minor
      Found in superset/viz.py - About 1 hr to fix

        Function process_metrics has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def process_metrics(self) -> None:
                # metrics in Viz is order sensitive, so metric_dict should be
                # OrderedDict
                self.metric_dict = OrderedDict()
                for mkey in METRIC_KEYS:
        Severity: Minor
        Found in superset/viz.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 apply_rolling has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def apply_rolling(self, df: pd.DataFrame) -> pd.DataFrame:
                rolling_type = self.form_data.get("rolling_type")
                rolling_periods = int(self.form_data.get("rolling_periods") or 0)
                min_periods = int(self.form_data.get("min_periods") or 0)
        
        
        Severity: Minor
        Found in superset/viz.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 get_df has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_df(self, query_obj: QueryObjectDict | None = None) -> pd.DataFrame:
                """Returns a pandas dataframe based on the query object"""
                if not query_obj:
                    query_obj = self.query_obj()
                if not query_obj:
        Severity: Minor
        Found in superset/viz.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 get_data has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_data(self, df: pd.DataFrame) -> VizData:
                if df.empty:
                    return None
        
                x = get_column_name(self.form_data.get("all_columns_x"))  # type: ignore
        Severity: Minor
        Found in superset/viz.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 query_obj has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def query_obj(self) -> QueryObjectDict:
                query_obj = super().query_obj()
                if len(query_obj["groupby"]) < len(self.form_data.get("groupby") or []) + len(
                    self.form_data.get("columns") or []
                ):
        Severity: Minor
        Found in superset/viz.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_data has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_data(self, df: pd.DataFrame) -> VizData:
                if df.empty:
                    return None
        
                label_col = self.form_data.get("mapbox_label")
        Severity: Minor
        Found in superset/viz.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 dedup_columns has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def dedup_columns(*columns_args: list[Column] | None) -> list[Column]:
                # dedup groupby and columns while preserving order
                labels: list[str] = []
                deduped_columns: list[Column] = []
                for columns in columns_args:
        Severity: Minor
        Found in superset/viz.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 get_data has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_data(self, df: pd.DataFrame) -> VizData:
                if df.empty:
                    return None
                groups = get_column_names(self.form_data.get("groupby"))
                time_op = self.form_data.get("time_series_option", "not_time")
        Severity: Minor
        Found in superset/viz.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 query_obj has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def query_obj(self) -> QueryObjectDict:
                # add NULL filters
                if self.form_data.get("filter_nulls", True):
                    self.add_null_filters()
        
        
        Severity: Minor
        Found in superset/viz.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 config["CACHE_DEFAULT_TIMEOUT"]
        Severity: Major
        Found in superset/viz.py - About 30 mins to fix

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

              def process_data(self, df: pd.DataFrame, aggregate: bool = False) -> VizData:
                  if df.empty:
                      return df
          
                  if aggregate:
          Severity: Minor
          Found in superset/viz.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 add_null_filters has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def add_null_filters(self) -> None:
                  spatial_columns = set()
                  for key in self.spatial_control_keys:
                      for column in self.get_spatial_columns(key):
                          spatial_columns.add(column)
          Severity: Minor
          Found in superset/viz.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 process_spatial_data_obj has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def process_spatial_data_obj(self, key: str, df: pd.DataFrame) -> pd.DataFrame:
                  spatial = self.form_data.get(key)
                  if spatial is None:
                      raise ValueError(_("Bad spatial key"))
          
          
          Severity: Minor
          Found in superset/viz.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