descriptors.py
1 from typing import Any 2 from typing import Set 3 4 from evidently.core.datasets import ColumnCondition 5 from evidently.tests.numerical_tests import ThresholdType 6 7 8 class EqualsColumnCondition(ColumnCondition): 9 expected: Any 10 11 def check(self, value: Any) -> bool: 12 try: 13 expected = type(value)(self.expected) 14 return expected == value 15 except (ValueError, TypeError): 16 return False 17 18 def get_default_alias(self, column: str) -> str: 19 return f"{column}: equals {self.expected}" 20 21 22 class NotEqualsColumnCondition(ColumnCondition): 23 expected: Any 24 25 def check(self, value: Any) -> bool: 26 try: 27 expected = type(value)(self.expected) 28 return expected != value 29 except (ValueError, TypeError): 30 return True 31 32 def get_default_alias(self, column: str) -> str: 33 return f"{column} not equals {self.expected}" 34 35 36 class LessColumnCondition(ColumnCondition): 37 threshold: ThresholdType 38 39 def check(self, value: Any) -> bool: 40 return value < self.threshold 41 42 def get_default_alias(self, column: str) -> str: 43 return f"{column}: less than {self.threshold}" 44 45 46 class LessEqualColumnCondition(ColumnCondition): 47 threshold: ThresholdType 48 49 def check(self, value: Any) -> bool: 50 return value <= self.threshold 51 52 def get_default_alias(self, column: str) -> str: 53 return f"{column}: less or equal to {self.threshold}" 54 55 56 class GreaterColumnCondition(ColumnCondition): 57 threshold: ThresholdType 58 59 def check(self, value: Any) -> bool: 60 return value > self.threshold 61 62 def get_default_alias(self, column: str) -> str: 63 return f"{column} greater than {self.threshold}" 64 65 66 class GreaterEqualColumnCondition(ColumnCondition): 67 threshold: ThresholdType 68 69 def check(self, value: Any) -> bool: 70 return value >= self.threshold 71 72 def get_default_alias(self, column: str) -> str: 73 return f"{column}: greater or equal to {self.threshold}" 74 75 76 def _typed_values(cls, values): 77 res = set() 78 for value in values: 79 try: 80 res.add(cls(value)) 81 except ValueError: 82 pass 83 return res 84 85 86 class IsInColumnCondition(ColumnCondition): 87 values: Set[Any] 88 89 def check(self, value: Any) -> bool: 90 return value in self.values or value in _typed_values(type(value), self.values) 91 92 def get_default_alias(self, column: str) -> str: 93 return f"{column} in list {self.values}" 94 95 96 class IsNotInColumnCondition(ColumnCondition): 97 values: Set[Any] 98 99 def check(self, value: Any) -> bool: 100 return value not in self.values and value not in _typed_values(type(value), self.values) 101 102 def get_default_alias(self, column: str) -> str: 103 return f"{column} not in list {self.values}"