Skip to content

Commit

Permalink
style: reformat using ruff and pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
dacopan committed Jul 2, 2024
1 parent 56b6b02 commit 606045c
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
from superset.db_engine_specs import BaseEngineSpec
from superset.models.core import Database


config = app.config
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -199,8 +200,7 @@ def _unique_constraints(cls) -> list[set[str]]:
for u in cls.__table_args__ # type: ignore
if isinstance(u, UniqueConstraint)
]
unique.extend(
{c.name} for c in cls.__table__.columns if c.unique) # type: ignore
unique.extend({c.name} for c in cls.__table__.columns if c.unique) # type: ignore
return unique

@classmethod
Expand Down Expand Up @@ -1028,7 +1028,7 @@ def assign_column_label(df: pd.DataFrame) -> Optional[pd.DataFrame]:
_("Db engine did not return all queried columns")
)
if len(df.columns) > len(labels_expected):
df = df.iloc[:, 0: len(labels_expected)]
df = df.iloc[:, 0 : len(labels_expected)]
df.columns = labels_expected
return df

Expand Down Expand Up @@ -1200,9 +1200,9 @@ def handle_single_value(value: Optional[FilterValue]) -> Optional[FilterValue]:
target_generic_type == utils.GenericDataType.NUMERIC
and operator
not in {
utils.FilterOperator.ILIKE,
utils.FilterOperator.LIKE,
}
utils.FilterOperator.ILIKE,
utils.FilterOperator.LIKE,
}
):
# For backwards compatibility and edge cases
# where a column data type might have changed
Expand Down Expand Up @@ -1448,8 +1448,7 @@ def convert_tbl_column_to_sqla_col(
col = self.make_sqla_column_compatible(col, label)
return col

def get_sqla_query(
# pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements
def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements
self,
apply_fetch_values_predicate: bool = False,
columns: Optional[list[Column]] = None,
Expand Down Expand Up @@ -1820,8 +1819,8 @@ def get_sqla_query(
if (
col_advanced_data_type != ""
and feature_flag_manager.is_feature_enabled(
"ENABLE_ADVANCED_DATA_TYPES"
)
"ENABLE_ADVANCED_DATA_TYPES"
)
and col_advanced_data_type in ADVANCED_DATA_TYPES
):
values = eq if is_list_target else [eq] # type: ignore
Expand Down Expand Up @@ -1874,9 +1873,9 @@ def get_sqla_query(
if (
op
not in {
utils.FilterOperator.EQUALS.value,
utils.FilterOperator.NOT_EQUALS.value,
}
utils.FilterOperator.EQUALS.value,
utils.FilterOperator.NOT_EQUALS.value,
}
and eq is None
):
raise QueryObjectValidationError(
Expand Down Expand Up @@ -1908,9 +1907,7 @@ def get_sqla_query(
where_clause_and.append(sqla_col.like(eq))
else:
where_clause_and.append(sqla_col.ilike(eq))
elif op in {
utils.FilterOperator.NOT_LIKE.value
}:
elif op in {utils.FilterOperator.NOT_LIKE.value}:
if target_generic_type != GenericDataType.STRING:
sqla_col = sa.cast(sqla_col, sa.String)

Expand Down Expand Up @@ -2120,22 +2117,21 @@ def get_sqla_query(

filter_columns = [flt.get("col") for flt in filter] if filter else []
rejected_filter_columns = [
col
for col in filter_columns
if col
and not is_adhoc_column(col)
and col not in self.column_names
and col not in applied_template_filters
] + rejected_adhoc_filters_columns
col
for col in filter_columns
if col
and not is_adhoc_column(col)
and col not in self.column_names
and col not in applied_template_filters
] + rejected_adhoc_filters_columns

applied_filter_columns = [
col
for col in filter_columns
if col
and not is_adhoc_column(col)
and (
col in self.column_names or col in applied_template_filters)
] + applied_adhoc_filters_columns
col
for col in filter_columns
if col
and not is_adhoc_column(col)
and (col in self.column_names or col in applied_template_filters)
] + applied_adhoc_filters_columns

return SqlaQuery(
applied_template_filters=applied_template_filters,
Expand Down

0 comments on commit 606045c

Please sign in to comment.