Skip to content

Commit

Permalink
[MAINTENANCE] expectations linting (great-expectations#6739)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kilo59 authored Jan 11, 2023
1 parent d121bb0 commit f5a76a3
Show file tree
Hide file tree
Showing 26 changed files with 77 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def get_validation_dependencies(

return validation_dependencies

def _validate(
def _validate( # noqa: C901 - 29
self,
configuration: ExpectationConfiguration,
metrics: Dict,
Expand Down Expand Up @@ -528,7 +528,7 @@ def _validate(
if "tail_weights" in partition_object:
partition_tail_weight_holdout = np.sum(partition_object["tail_weights"])
else:
partition_tail_weight_holdout = 0
partition_tail_weight_holdout = 0 # noqa: F841 # unused

expected_weights = np.array(partition_object["weights"]) * (
1 - tail_weight_holdout - internal_weight_holdout
Expand Down Expand Up @@ -1152,7 +1152,7 @@ def _prescriptive_renderer(
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
styling = runtime_configuration.get("styling")
_ = runtime_configuration.get("styling")
params = substitute_none_for_missing(
configuration.kwargs,
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ def _prescriptive_renderer(
**kwargs,
):
runtime_configuration = runtime_configuration or {}
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
_ = False if runtime_configuration.get("include_column_name") is False else True
styling = runtime_configuration.get("styling")
params = substitute_none_for_missing(
configuration.kwargs, ["column_A", "column_B"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ def _prescriptive_renderer(
**kwargs,
):
runtime_configuration = runtime_configuration or {}
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
_ = False if runtime_configuration.get("include_column_name") is False else True
styling = runtime_configuration.get("styling")
params = substitute_none_for_missing(
configuration.kwargs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ def _prescriptive_renderer(
**kwargs,
):
runtime_configuration = runtime_configuration or {}
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
_ = False if runtime_configuration.get("include_column_name") is False else True
styling = runtime_configuration.get("styling")
params = substitute_none_for_missing(
configuration.kwargs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def _prescriptive_renderer(
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
styling = runtime_configuration.get("styling")
_ = runtime_configuration.get("styling")
params = substitute_none_for_missing(
configuration["kwargs"],
["column", "quantile_ranges", "row_condition", "condition_parser"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def _prescriptive_renderer(
)
]

def _validate_pandas(
def _validate_pandas( # noqa: C901 - 16
self,
actual_column_type,
expected_types_list,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _prescriptive_renderer(
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
styling = runtime_configuration.get("styling")
_ = runtime_configuration.get("styling")
params = substitute_none_for_missing(
configuration.kwargs,
["column", "mostly", "json_schema", "row_condition", "condition_parser"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,9 @@ def _prescriptive_renderer(
**kwargs
) -> None:
runtime_configuration = runtime_configuration or {}
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
styling = runtime_configuration.get("styling")
params = substitute_none_for_missing(
_ = False if runtime_configuration.get("include_column_name") is False else True
_ = runtime_configuration.get("styling")
params = substitute_none_for_missing( # noqa: F841 # unused
configuration.kwargs,
["column", "mostly", "row_condition", "condition_parser"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,9 @@ def _prescriptive_renderer(
**kwargs
) -> None:
runtime_configuration = runtime_configuration or {}
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
styling = runtime_configuration.get("styling")
params = substitute_none_for_missing(
_ = False if runtime_configuration.get("include_column_name") is False else True
_ = runtime_configuration.get("styling")
params = substitute_none_for_missing( # noqa: F841 # unused
configuration.kwargs,
["column", "mostly", "row_condition", "condition_parser"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def _prescriptive_renderer(
template_str = f"{conditional_template_str}, then {template_str}"
params.update(conditional_params)

params_with_json_schema = {
params_with_json_schema = { # noqa: F841 # unused
"column": {"schema": {"type": "string"}, "value": params.get("column")},
"mostly": {"schema": {"type": "number"}, "value": params.get("mostly")},
"mostly_pct": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,9 @@ def _prescriptive_renderer(
**kwargs
) -> None:
runtime_configuration = runtime_configuration or {}
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
styling = runtime_configuration.get("styling")
params = substitute_none_for_missing(
_ = False if runtime_configuration.get("include_column_name") is False else True
_ = runtime_configuration.get("styling")
params = substitute_none_for_missing( # noqa: F841 # unused
configuration.kwargs,
["column", "mostly", "row_condition", "condition_parser"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,9 @@ def _prescriptive_renderer(
**kwargs
) -> None:
runtime_configuration = runtime_configuration or {}
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
styling = runtime_configuration.get("styling")
params = substitute_none_for_missing(
_ = False if runtime_configuration.get("include_column_name") is False else True
_ = runtime_configuration.get("styling")
params = substitute_none_for_missing( # noqa: F841 # unused
configuration.kwargs,
["column", "mostly", "row_condition", "condition_parser"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ def _prescriptive_renderer(
**kwargs,
):
runtime_configuration = runtime_configuration or {}
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
_ = False if runtime_configuration.get("include_column_name") is False else True
styling = runtime_configuration.get("styling")

# NOTE: This expectation is deprecated, please use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ def _prescriptive_renderer(
**kwargs,
):
runtime_configuration = runtime_configuration or {}
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
_ = False if runtime_configuration.get("include_column_name") is False else True
styling = runtime_configuration.get("styling")

params = substitute_none_for_missing(
Expand All @@ -177,9 +175,9 @@ def _prescriptive_renderer(
)

if params["mostly"] is not None and params["mostly"] < 1.0:
params_with_json_schema["mostly_pct"]["value"] = num_to_str(
params["mostly"] * 100, precision=15, no_scientific=True
)
params_with_json_schema["mostly_pct"][ # noqa: F821 # FIXME: this breaks
"value"
] = num_to_str(params["mostly"] * 100, precision=15, no_scientific=True)
template_str = "Values must be unique across columns, at least $mostly_pct % of the time: "
else:
template_str = "Values must always be unique across columns: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ def _prescriptive_renderer(
**kwargs,
):
runtime_configuration = runtime_configuration or {}
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
_ = False if runtime_configuration.get("include_column_name") is False else True
styling = runtime_configuration.get("styling")
params = substitute_none_for_missing(
configuration.kwargs,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Dict, Optional
from typing import Dict, Optional

from great_expectations.core import (
ExpectationConfiguration,
Expand All @@ -18,9 +18,6 @@
)
from great_expectations.render.util import substitute_none_for_missing

if TYPE_CHECKING:
from great_expectations.render.renderer_configuration import AddParamArgs


class ExpectTableColumnCountToEqual(TableExpectation):
"""Expect the number of columns to equal a value.
Expand Down Expand Up @@ -133,9 +130,7 @@ def _prescriptive_renderer(
**kwargs,
):
runtime_configuration = runtime_configuration or {}
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
_ = False if runtime_configuration.get("include_column_name") is False else True
styling = runtime_configuration.get("styling")
params = substitute_none_for_missing(configuration.kwargs, ["value"])
template_str = "Must have exactly $value columns."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from itertools import zip_longest
from typing import TYPE_CHECKING, Dict, Optional
from typing import Dict, Optional

from great_expectations.core import (
ExpectationConfiguration,
Expand All @@ -19,9 +19,6 @@
)
from great_expectations.render.util import substitute_none_for_missing

if TYPE_CHECKING:
from great_expectations.render.renderer_configuration import AddParamArgs


class ExpectTableColumnsToMatchOrderedList(TableExpectation):
"""Expect the columns to exactly match a specified list.
Expand Down Expand Up @@ -158,9 +155,7 @@ def _prescriptive_renderer(
**kwargs,
):
runtime_configuration = runtime_configuration or {}
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
_ = False if runtime_configuration.get("include_column_name") is False else True
styling = runtime_configuration.get("styling")
params = substitute_none_for_missing(configuration.kwargs, ["column_list"])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ def _prescriptive_renderer(
**kwargs,
):
runtime_configuration = runtime_configuration or {}
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
_ = False if runtime_configuration.get("include_column_name") is False else True
styling = runtime_configuration.get("styling")
params = substitute_none_for_missing(
configuration.kwargs, ["column_set", "exact_match"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ def _prescriptive_renderer(
**kwargs,
):
runtime_configuration = runtime_configuration or {}
include_column_name = (
False if runtime_configuration.get("include_column_name") is False else True
)
_ = False if runtime_configuration.get("include_column_name") is False else True
styling = runtime_configuration.get("styling")
params = substitute_none_for_missing(
configuration.kwargs, # type: ignore[union-attr]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from copy import deepcopy
from typing import TYPE_CHECKING, Dict, Optional
from typing import Dict, Optional

from great_expectations.core import (
ExpectationConfiguration,
Expand All @@ -24,9 +24,6 @@
from great_expectations.validator.metric_configuration import MetricConfiguration
from great_expectations.validator.validator import ValidationDependencies

if TYPE_CHECKING:
from great_expectations.render.renderer_configuration import AddParamArgs


class ExpectTableRowCountToEqualOtherTable(TableExpectation):
"""Expect the number of rows to equal the number in another table.
Expand Down
36 changes: 22 additions & 14 deletions great_expectations/expectations/expectation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,11 +1255,15 @@ def run_diagnostics(
"""

if debug_logger is not None:
_debug = lambda x: debug_logger.debug(f"(run_diagnostics) {x}")
_error = lambda x: debug_logger.error(f"(run_diagnostics) {x}")
_debug = lambda x: debug_logger.debug( # noqa: E731
f"(run_diagnostics) {x}"
)
_error = lambda x: debug_logger.error( # noqa: E731
f"(run_diagnostics) {x}"
)
else:
_debug = lambda x: x
_error = lambda x: x
_debug = lambda x: x # noqa: E731
_error = lambda x: x # noqa: E731

library_metadata: AugmentedLibraryMetadata = (
self._get_augmented_library_metadata()
Expand Down Expand Up @@ -1481,8 +1485,8 @@ def _get_examples(
top_level_suppress_test_for = example.get("suppress_test_for")
for test in example["tests"]:
if (
test.get("include_in_gallery") == True
or return_only_gallery_examples == False
test.get("include_in_gallery") == True # noqa: E712
or return_only_gallery_examples == False # noqa: E712
):
copied_test = deepcopy(test)
if top_level_only_for:
Expand Down Expand Up @@ -1737,11 +1741,15 @@ def _get_test_results(
"""Generate test results. This is an internal method for run_diagnostics."""

if debug_logger is not None:
_debug = lambda x: debug_logger.debug(f"(_get_test_results) {x}")
_error = lambda x: debug_logger.error(f"(_get_test_results) {x}")
_debug = lambda x: debug_logger.debug( # noqa: E731
f"(_get_test_results) {x}"
)
_error = lambda x: debug_logger.error( # noqa: E731
f"(_get_test_results) {x}"
)
else:
_debug = lambda x: x
_error = lambda x: x
_debug = lambda x: x # noqa: E731
_error = lambda x: x # noqa: E731
_debug("Starting")

test_results = []
Expand Down Expand Up @@ -1841,7 +1849,7 @@ def _get_test_results(

return test_results

def _get_rendered_result_as_string(self, rendered_result) -> str:
def _get_rendered_result_as_string(self, rendered_result) -> str: # noqa: C901 - 16
"""Convenience method to get rendered results as strings."""

result: str = ""
Expand Down Expand Up @@ -1887,7 +1895,7 @@ def _get_rendered_result_as_string(self, rendered_result) -> str:
elif isinstance(rendered_result, int):
result = repr(rendered_result)

elif rendered_result == None:
elif rendered_result is None:
result = ""

else:
Expand Down Expand Up @@ -2232,7 +2240,7 @@ def validate_metric_value_between_configuration(

return True

def _validate_metric_value_between(
def _validate_metric_value_between( # noqa: C901 - 21
self,
metric_name,
configuration: ExpectationConfiguration,
Expand Down Expand Up @@ -3176,7 +3184,7 @@ def _validate(
)


def _format_map_output(
def _format_map_output( # noqa: C901 - 22
result_format: dict,
success: bool,
element_count: Optional[int] = None,
Expand Down
2 changes: 1 addition & 1 deletion great_expectations/expectations/metrics/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
)
from collections import namedtuple

BigQueryTypes = namedtuple("BigQueryTypes", sorted(sqla_bigquery._type_map))
BigQueryTypes = namedtuple("BigQueryTypes", sorted(sqla_bigquery._type_map)) # type: ignore[misc] # cannot infer sorted return type
bigquery_types_tuple = BigQueryTypes(**sqla_bigquery._type_map)
except ImportError:
sqla_bigquery = None
Expand Down
Loading

0 comments on commit f5a76a3

Please sign in to comment.