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

Refactor: target_matrix setup #75

Open
wants to merge 2 commits into
base: mainline
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 12 additions & 1 deletion tests/monitor/manager/test_monitor_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,18 @@ def test_set_non_iso_data_readiness_raises(monitor_setup) -> None:
with pytest.raises(ValueError):
monitor_setup.data_readiness_duration = "Some non-conformant string"


def test_column_matrix_has_at_least_one_group(monitor_setup) -> None:
monitor_setup.config = DriftConfig(
metric = ComplexMetrics.histogram,
threshold = 0.6,
baseline = ReferenceProfileId(profileId="test_prof")
)

monitor_setup.apply()

assert isinstance(monitor_setup.target_matrix, ColumnMatrix)
assert monitor_setup.target_matrix.include == ["*"]

def test_cron_schedule_for_analyzer(monitor_setup) -> None:
monitor_setup.config = FixedThresholdsConfig(
metric=DatasetMetric.classification_accuracy,
Expand Down
24 changes: 7 additions & 17 deletions whylabs_toolkit/monitor/manager/monitor_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ def __init__(self, monitor_id: str, dataset_id: Optional[str] = None, config: Co
self._monitor_mode: Optional[Union[EveryAnomalyMode, DigestMode]] = None
self._monitor_actions: List[GlobalAction] = []
self._analyzer_schedule: Optional[Union[FixedCadenceSchedule, CronSchedule]] = None
self._target_columns: Optional[List[str]] = []
self._target_columns: Optional[List[str]] = ["*"]
self._exclude_columns: Optional[List[str]] = []
self._target_matrix: Union[ColumnMatrix, DatasetMatrix] = ColumnMatrix(

self._default_column_matrix = ColumnMatrix(
include=self._target_columns, exclude=self._exclude_columns, segments=[]
)

self._target_matrix: Union[ColumnMatrix, DatasetMatrix] = self._default_column_matrix
self._analyzer_config: Union[
DiffConfig,
FixedThresholdsConfig,
Expand Down Expand Up @@ -237,9 +240,7 @@ def set_target_columns(self, columns: List[str]) -> None:
def exclude_target_columns(self, columns: List[str]) -> None:
if self._validate_columns_input(columns=columns):
self._exclude_columns = columns
self._target_matrix = self._target_matrix or ColumnMatrix(
include=self._target_columns, exclude=self._exclude_columns, segments=[]
)
self._target_matrix = self._target_matrix or self._default_column_matrix
if isinstance(self._target_matrix, ColumnMatrix):
self._target_matrix.exclude = self._exclude_columns

Expand All @@ -254,8 +255,6 @@ def set_fixed_dates_baseline(self, start_date: datetime, end_date: datetime) ->
)

def __set_analyzer(self) -> None:
self.__configure_target_matrix()

self.__set_dataset_matrix_for_dataset_metric()
self.__set_dataset_matrix_for_missing_data_metric()

Expand Down Expand Up @@ -288,11 +287,6 @@ def __set_monitor(
actions=monitor_actions,
)

def __configure_target_matrix(self) -> None:
self._target_matrix = self._target_matrix or ColumnMatrix(
include=self._target_columns or ["*"], exclude=self._exclude_columns, segments=[]
)

def __set_dataset_matrix_for_dataset_metric(self) -> None:
if self._analyzer_config:
if isinstance(self._analyzer_config, (ConjunctionConfig, DisjunctionConfig)):
Expand All @@ -313,11 +307,7 @@ def __set_dataset_matrix_for_dataset_metric(self) -> None:
"Setting a DatasetMatrix requires a DatasetMetric to be used"
"Changing it to an empty ColumnMatrix instead"
)
self._target_matrix = ColumnMatrix(
include=self._target_columns or ["*"],
exclude=self._exclude_columns,
segments=self._target_matrix.segments,
)
self._target_matrix = self._default_column_matrix
return None

def __set_dataset_matrix_for_missing_data_metric(self) -> None:
Expand Down
Loading