Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAINTENANCE] Column Descriptive Metrics: Remove compute_metrics_with_aborted_metrics #8865

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import TYPE_CHECKING, Dict, Optional, Tuple
from typing import TYPE_CHECKING, Dict, Optional

import altair as alt
import numpy as np
Expand Down Expand Up @@ -44,9 +44,11 @@
parse_row_condition_string_pandas_engine,
substitute_none_for_missing,
)
from great_expectations.validator.computed_metric import MetricValue # noqa: TCH001
from great_expectations.validator.metric_configuration import MetricConfiguration
from great_expectations.validator.metrics_calculator import MetricsCalculator
from great_expectations.validator.metrics_calculator import (
MetricsCalculator,
_MetricsDict,
)
from great_expectations.validator.validator import (
ValidationDependencies,
)
Expand Down Expand Up @@ -248,9 +250,8 @@ def get_validation_dependencies(
execution_engine=execution_engine,
show_progress_bars=True,
)
resolved_metrics: Dict[
Tuple[str, str, str], MetricValue
] = metrics_calculator.compute_metrics(
resolved_metrics: _MetricsDict
resolved_metrics, _ = metrics_calculator.compute_metrics(
metric_configurations=[partition_metric_configuration],
runtime_configuration=None,
min_graph_edges_pbar_enable=0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def _compute_metrics(
(
computed_metrics,
aborted_metrics,
) = validator.compute_metrics_with_aborted_metrics(
) = validator.compute_metrics(
metric_configurations=metric_configs,
runtime_configuration={"catch_exceptions": True},
)
Expand Down
8 changes: 5 additions & 3 deletions great_expectations/rule_based_profiler/helpers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
from great_expectations.data_context.data_context.abstract_data_context import (
AbstractDataContext,
)
from great_expectations.validator.metrics_calculator import (
_MetricsDict,
)
from great_expectations.validator.validator import Validator

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -360,9 +363,8 @@ def get_resolved_metrics_by_key(

# Step 1: Gather "MetricConfiguration" objects corresponding to all possible key values/combinations.
# and compute all metric values (resolve "MetricConfiguration" objects ) using a single method call.
resolved_metrics: Dict[
Tuple[str, str, str], MetricValue
] = validator.compute_metrics(
resolved_metrics: _MetricsDict
resolved_metrics, _ = validator.compute_metrics(
metric_configurations=[
metric_configuration
for key, metric_configurations_for_key in metric_configurations_by_key.items()
Expand Down
39 changes: 8 additions & 31 deletions great_expectations/validator/metrics_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def get_metrics(
Returns:
Return Dictionary with requested metrics resolved, with metric_name as key and computed metric as value.
"""
resolved_metrics: _MetricsDict = self.compute_metrics(
resolved_metrics: _MetricsDict
resolved_metrics, _ = self.compute_metrics(
metric_configurations=list(metrics.values()),
runtime_configuration=None,
min_graph_edges_pbar_enable=0,
Expand All @@ -148,7 +149,7 @@ def get_metrics(
for metric_configuration in metrics.values()
}

def compute_metrics_with_aborted_metrics(
def compute_metrics(
self,
metric_configurations: List[MetricConfiguration],
runtime_configuration: Optional[dict] = None,
Expand All @@ -162,7 +163,9 @@ def compute_metrics_with_aborted_metrics(
min_graph_edges_pbar_enable: Minumum number of graph edges to warrant showing progress bars.

Returns:
Dictionary with requested metrics resolved, with unique metric ID as key and computed metric as value.
Tuple of two elements, the first is a dictionary with requested metrics resolved,
with unique metric ID as key and computed metric as value. The second is a dictionary of the
aborted metrics information, with metric ID as key if any metrics were aborted.
"""
graph: ValidationGraph = self.build_metric_dependency_graph(
metric_configurations=metric_configurations,
Expand All @@ -172,39 +175,13 @@ def compute_metrics_with_aborted_metrics(
aborted_metrics_info: _AbortedMetricsInfoDict
(
resolved_metrics,
aborted_metrics_info,
aborted_metrics,
) = self.resolve_validation_graph_and_handle_aborted_metrics_info(
graph=graph,
runtime_configuration=runtime_configuration,
min_graph_edges_pbar_enable=min_graph_edges_pbar_enable,
)
return resolved_metrics, aborted_metrics_info

def compute_metrics(
self,
metric_configurations: List[MetricConfiguration],
runtime_configuration: Optional[dict] = None,
min_graph_edges_pbar_enable: int = 0,
# Set to low number (e.g., 3) to suppress progress bar for small graphs.
) -> _MetricsDict:
"""
Args:
metric_configurations: List of desired MetricConfiguration objects to be resolved.
runtime_configuration: Additional run-time settings (see "Validator.DEFAULT_RUNTIME_CONFIGURATION").
min_graph_edges_pbar_enable: Minumum number of graph edges to warrant showing progress bars.

Returns:
Dictionary with requested metrics resolved, with unique metric ID as key and computed metric as value.
"""

# Note: Dropping aborted metrics for backward compatibility.
# This is a temporary solution until we can change all the callers to handle aborted metrics.
resolved_metrics, _ = self.compute_metrics_with_aborted_metrics(
metric_configurations=metric_configurations,
runtime_configuration=runtime_configuration,
min_graph_edges_pbar_enable=min_graph_edges_pbar_enable,
)
return resolved_metrics
return resolved_metrics, aborted_metrics

def build_metric_dependency_graph(
self,
Expand Down
32 changes: 4 additions & 28 deletions great_expectations/validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,30 +357,6 @@ def compute_metrics(
runtime_configuration: Optional[dict] = None,
min_graph_edges_pbar_enable: int = 0,
# Set to low number (e.g., 3) to suppress progress bar for small graphs.
) -> _MetricsDict:
"""
Convenience method that computes requested metrics (specified as elements of "MetricConfiguration" list).

Args:
metric_configurations: List of desired MetricConfiguration objects to be resolved.
runtime_configuration: Additional run-time settings (see "Validator.DEFAULT_RUNTIME_CONFIGURATION").
min_graph_edges_pbar_enable: Minumum number of graph edges to warrant showing progress bars.

Returns:
Dictionary with requested metrics resolved, with unique metric ID as key and computed metric as value.
"""
return self._metrics_calculator.compute_metrics(
metric_configurations=metric_configurations,
runtime_configuration=runtime_configuration,
min_graph_edges_pbar_enable=min_graph_edges_pbar_enable,
)

def compute_metrics_with_aborted_metrics(
self,
metric_configurations: List[MetricConfiguration],
runtime_configuration: Optional[dict] = None,
min_graph_edges_pbar_enable: int = 0,
# Set to low number (e.g., 3) to suppress progress bar for small graphs.
) -> tuple[_MetricsDict, _AbortedMetricsInfoDict]:
"""
Convenience method that computes requested metrics (specified as elements of "MetricConfiguration" list).
Expand All @@ -391,11 +367,11 @@ def compute_metrics_with_aborted_metrics(
min_graph_edges_pbar_enable: Minumum number of graph edges to warrant showing progress bars.

Returns:
Tuple with two elements. The first is a dictionary with requested metrics resolved, with unique metric
ID as key and computed metric as value. The second is a dictionary with information about any metrics
that were aborted during computation, using the unique metric ID as key.
Tuple of two elements, the first is a dictionary with requested metrics resolved,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

with unique metric ID as key and computed metric as value. The second is a dictionary of the
aborted metrics information, with metric ID as key if any metrics were aborted.
"""
return self._metrics_calculator.compute_metrics_with_aborted_metrics(
return self._metrics_calculator.compute_metrics(
metric_configurations=metric_configurations,
runtime_configuration=runtime_configuration,
min_graph_edges_pbar_enable=min_graph_edges_pbar_enable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_get_metrics():
("column_values.null.count", "column=col2", ()): 1,
}
aborted_metrics = {}
mock_validator.compute_metrics_with_aborted_metrics.return_value = (
mock_validator.compute_metrics.return_value = (
computed_metrics,
aborted_metrics,
)
Expand Down Expand Up @@ -182,7 +182,7 @@ def test_get_metrics_metrics_missing():
("column_values.null.count", "column=col2", ()): 1,
}
mock_aborted_metrics = {}
mock_validator.compute_metrics_with_aborted_metrics.return_value = (
mock_validator.compute_metrics.return_value = (
mock_computed_metrics,
mock_aborted_metrics,
)
Expand Down Expand Up @@ -344,7 +344,7 @@ def test_get_metrics_with_exception():
("column_values.null.count", "column=col1", ()): 1,
("column_values.null.count", "column=col2", ()): 1,
}
mock_validator.compute_metrics_with_aborted_metrics.return_value = (
mock_validator.compute_metrics.return_value = (
computed_metrics,
aborted_metrics,
)
Expand Down Expand Up @@ -502,7 +502,7 @@ def test_get_metrics_with_column_type_missing():
("column_values.null.count", "column=col1", ()): 1,
("column_values.null.count", "column=col2", ()): 1,
}
mock_validator.compute_metrics_with_aborted_metrics.return_value = (
mock_validator.compute_metrics.return_value = (
computed_metrics,
aborted_metrics,
)
Expand Down Expand Up @@ -642,7 +642,7 @@ def test_get_metrics_only_gets_a_validator_once():
("column_values.null.count", "column=col1", ()): 1,
("column_values.null.count", "column=col2", ()): 1,
}
mock_validator.compute_metrics_with_aborted_metrics.return_value = (
mock_validator.compute_metrics.return_value = (
computed_metrics,
aborted_metrics,
)
Expand Down
8 changes: 6 additions & 2 deletions tests/validator/test_metrics_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def test_column_partition_metric(
"allow_relative_error": False,
},
)
results = metrics_calculator.compute_metrics(metric_configurations=[desired_metric])
results, _ = metrics_calculator.compute_metrics(
metric_configurations=[desired_metric]
)

increment = float(n_bins + 1) / n_bins
assert all(
Expand All @@ -112,7 +114,9 @@ def test_column_partition_metric(
"allow_relative_error": False,
},
)
results = metrics_calculator.compute_metrics(metric_configurations=[desired_metric])
results, _ = metrics_calculator.compute_metrics(
metric_configurations=[desired_metric]
)

increment = datetime.timedelta(
seconds=(seconds_in_week * float(n_bins + 1) / n_bins)
Expand Down
Loading