whylogs.core.constraints.metric_constraints#

Module Contents#

Classes#

MetricsSelector

MetricConstraint

DatasetComparisonConstraint

Implements dataset-level constraints that require a reference dataset to

DatasetConstraint

Implements dataset-level constraints that are not attached to a specific

MetricConstraintWrapper

Converts a MetricConstraint not associated with a specific column

PrefixCondition

Interpret expressions in the form used to serialize Predicate expressions.

Constraints

ConstraintsBuilder

Functions#

pretty_display(→ Dict[str, Any])

Attributes#

whylogs.core.constraints.metric_constraints.logger#
whylogs.core.constraints.metric_constraints.ReportResult#
class whylogs.core.constraints.metric_constraints.MetricsSelector#
metric_name: str#
column_name: Optional[str]#
metrics_resolver: Optional[Callable[[whylogs.core.view.dataset_profile_view.DatasetProfileView], List[whylogs.core.metrics.metrics.Metric]]]#
column_profile(profile: Optional[whylogs.core.view.dataset_profile_view.DatasetProfileView]) Optional[whylogs.core.view.column_profile_view.ColumnProfileView]#
Parameters

profile (Optional[whylogs.core.view.dataset_profile_view.DatasetProfileView]) –

Return type

Optional[whylogs.core.view.column_profile_view.ColumnProfileView]

apply(profile: whylogs.core.view.dataset_profile_view.DatasetProfileView) List[whylogs.core.metrics.metrics.Metric]#
Parameters

profile (whylogs.core.view.dataset_profile_view.DatasetProfileView) –

Return type

List[whylogs.core.metrics.metrics.Metric]

whylogs.core.constraints.metric_constraints.pretty_display(metric_name: str, summary: Dict[str, Any]) Dict[str, Any]#
Parameters
  • metric_name (str) –

  • summary (Dict[str, Any]) –

Return type

Dict[str, Any]

class whylogs.core.constraints.metric_constraints.MetricConstraint#
condition: Callable[[whylogs.core.metrics.metrics.Metric], bool]#
name: str#
metric_selector: MetricsSelector#
require_column_existence: bool = True#
validate(dataset_profile: whylogs.core.view.dataset_profile_view.DatasetProfileView) bool#
Parameters

dataset_profile (whylogs.core.view.dataset_profile_view.DatasetProfileView) –

Return type

bool

validate_profile(dataset_profile: whylogs.core.view.dataset_profile_view.DatasetProfileView) Tuple[bool, Optional[Dict[str, Any]]]#
Parameters

dataset_profile (whylogs.core.view.dataset_profile_view.DatasetProfileView) –

Return type

Tuple[bool, Optional[Dict[str, Any]]]

exception whylogs.core.constraints.metric_constraints.MissingMetric#

Bases: Exception

DatasetConstraint conditions can raise this exception to indicate that a required metric or column could not be found in the DatasetProfileView. The DatasetConstraint is responsible for handling this exception.

class args#
with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class whylogs.core.constraints.metric_constraints.DatasetComparisonConstraint#

Implements dataset-level constraints that require a reference dataset to be compared against. The condition Callable takes the DatasetProfileView of the dataset to be validated as well as the DatasetProfileView of the reference dataset and returns a boolean indicating whether the condition is satisfied as well as a dictionary with summary information about the validation.

condition: Callable[[whylogs.core.view.dataset_profile_view.DatasetProfileView, whylogs.core.view.dataset_profile_view.DatasetProfileView], Tuple[bool, Dict[str, whylogs.core.metrics.metrics.Metric]]]#
name: str#
validate_profile(dataset_profile: whylogs.core.view.dataset_profile_view.DatasetProfileView, reference_profile: whylogs.core.view.dataset_profile_view.DatasetProfileView) Tuple[bool, Optional[Dict[str, Any]]]#
Parameters
Return type

Tuple[bool, Optional[Dict[str, Any]]]

class whylogs.core.constraints.metric_constraints.DatasetConstraint#

Implements dataset-level constraints that are not attached to a specific metric or column. The condition Callable takes the DatasetProfileView as input and returns a boolean indicating whether the condition is satisfied as well as a dictionary mapping ‘column_name/metric_namespace’ -> Metric for any metrics the condition used during its evaluation.

condition: Callable[[whylogs.core.view.dataset_profile_view.DatasetProfileView], Tuple[bool, Dict[str, whylogs.core.metrics.metrics.Metric]]]#
name: str#
require_column_existence: bool = True#
validate_profile(dataset_profile: whylogs.core.view.dataset_profile_view.DatasetProfileView) Tuple[bool, Optional[Dict[str, Any]]]#
Parameters

dataset_profile (whylogs.core.view.dataset_profile_view.DatasetProfileView) –

Return type

Tuple[bool, Optional[Dict[str, Any]]]

class whylogs.core.constraints.metric_constraints.MetricConstraintWrapper(constraint: MetricConstraint)#

Converts a MetricConstraint not associated with a specific column into a Callable that can be a DatasetConstraint condition.

Parameters

constraint (MetricConstraint) –

class whylogs.core.constraints.metric_constraints.PrefixCondition(expression: str, cfg: Optional[whylogs.core.configs.SummaryConfig] = None)#

Interpret expressions in the form used to serialize Predicate expressions. This is probably a reasonable serialization format for DatasetConstraint conditions, but might not be the best user interface for creating conditions in client code.

Parameters
class whylogs.core.constraints.metric_constraints.Constraints(dataset_profile_view: Optional[whylogs.core.view.dataset_profile_view.DatasetProfileView] = None, column_constraints: Optional[Dict[str, Dict[str, MetricConstraint]]] = None, reference_profile_view: Optional[whylogs.core.view.dataset_profile_view.DatasetProfileView] = None)#
Parameters
column_constraints: Dict[str, Dict[str, MetricConstraint]]#
dataset_constraints: List[DatasetConstraint]#
dataset_comparison_constraints: List[DatasetComparisonConstraint]#
dataset_profile_view: Optional[whylogs.core.view.dataset_profile_view.DatasetProfileView]#
validate(profile_view: Optional[whylogs.core.view.dataset_profile_view.DatasetProfileView] = None) bool#
Parameters

profile_view (Optional[whylogs.core.view.dataset_profile_view.DatasetProfileView]) –

Return type

bool

set_reference_profile_view(profile_view: whylogs.core.view.dataset_profile_view.DatasetProfileView) None#
Parameters

profile_view (whylogs.core.view.dataset_profile_view.DatasetProfileView) –

Return type

None

report(profile_view: Optional[whylogs.core.view.dataset_profile_view.DatasetProfileView] = None) List[Tuple[str, int, int]]#
Parameters

profile_view (Optional[whylogs.core.view.dataset_profile_view.DatasetProfileView]) –

Return type

List[Tuple[str, int, int]]

generate_constraints_report(profile_view: Optional[whylogs.core.view.dataset_profile_view.DatasetProfileView] = None, with_summary=False) List[ReportResult]#
Parameters

profile_view (Optional[whylogs.core.view.dataset_profile_view.DatasetProfileView]) –

Return type

List[ReportResult]

class whylogs.core.constraints.metric_constraints.ConstraintsBuilder(dataset_profile_view: whylogs.core.view.dataset_profile_view.DatasetProfileView, constraints: Optional[Constraints] = None, reference_profile_view: Optional[whylogs.core.view.dataset_profile_view.DatasetProfileView] = None)#
Parameters
get_metric_selectors() List[MetricsSelector]#
Return type

List[MetricsSelector]

add_constraints(constraints: List[Union[MetricConstraint, DatasetConstraint]]) ConstraintsBuilder#
Parameters

constraints (List[Union[MetricConstraint, DatasetConstraint]]) –

Return type

ConstraintsBuilder

add_constraint(constraint: Union[MetricConstraint, DatasetConstraint], ignore_missing: bool = False) ConstraintsBuilder#
Parameters
Return type

ConstraintsBuilder

build() Constraints#
Return type

Constraints