From 0c4ddff3a099c4576da52c2db5e96edd8ba26165 Mon Sep 17 00:00:00 2001 From: Vyacheslav Morov Date: Mon, 12 Aug 2024 21:38:14 +0200 Subject: [PATCH] Fix HuggingFaceFeature / CustomEvals hash error. (#1248) * Fix HuggingFaceFeature hash error. * Fix CustomEvals hash error. --- src/evidently/features/hf_feature.py | 3 +++ src/evidently/pydantic_utils.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/evidently/features/hf_feature.py b/src/evidently/features/hf_feature.py index 8f65d92ffa..3ccb1b03e9 100644 --- a/src/evidently/features/hf_feature.py +++ b/src/evidently/features/hf_feature.py @@ -35,6 +35,9 @@ def generate_data(self, data: pd.DataFrame, data_definition: DataDefinition) -> result = func(data[self.column_name], **{param: self.params.get(param, None) for param in available_params}) return result + def __hash__(self): + return DataFeature.__hash__(self) + class HuggingFaceToxicityFeature(DataFeature): __feature_type__: ClassVar = ColumnType.Numerical diff --git a/src/evidently/pydantic_utils.py b/src/evidently/pydantic_utils.py index 006e779698..feefd29510 100644 --- a/src/evidently/pydantic_utils.py +++ b/src/evidently/pydantic_utils.py @@ -8,6 +8,7 @@ from functools import lru_cache from typing import TYPE_CHECKING from typing import Any +from typing import Callable from typing import ClassVar from typing import Dict from typing import FrozenSet @@ -223,6 +224,8 @@ def get_value_fingerprint(value: Any) -> FingerprintPart: return tuple(get_value_fingerprint(v) for v in value) if isinstance(value, (set, frozenset)): return tuple(get_value_fingerprint(v) for v in sorted(value, key=str)) + if isinstance(value, Callable): # type: ignore + return hash(value) raise NotImplementedError( f"Not implemented for value of type {value.__class__.__module__}.{value.__class__.__name__}" )