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

Fix duplicate init ResolverSpec registration warning in has_patterns #178

Merged
merged 1 commit into from
Oct 30, 2023
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ env.bak/
venv.bak/
pythonenv*
.dockerignore
langkit/langkit_data/

# Spyder project settings
.spyderproject
Expand Down
13 changes: 12 additions & 1 deletion langkit/regexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from . import LangKitConfig, lang_config, prompt_column, response_column
from whylogs.core.metrics.metrics import FrequentItemsMetric
from whylogs.core.resolvers import MetricSpec
from typing import List, Optional
from typing import Dict, List, Optional

diagnostic_logger = getLogger(__name__)

Expand Down Expand Up @@ -52,6 +52,8 @@ def _unregister_metric_udf(old_name: str, namespace: Optional[str] = ""):


def _register_udfs(config: Optional[LangKitConfig] = None):
from whylogs.experimental.core.udf_schema import _resolver_specs

global _registered
if _registered and config is None:
return
Expand All @@ -61,8 +63,17 @@ def _register_udfs(config: Optional[LangKitConfig] = None):
pattern_metric_name = config.metric_name_map.get(
default_metric_name, default_metric_name
)

for old in _registered:
_unregister_metric_udf(old_name=old)
if (
_resolver_specs is not None
and isinstance(_resolver_specs, Dict)
and isinstance(_resolver_specs[""], List)
):
_resolver_specs[""] = [
spec for spec in _resolver_specs[""] if spec.column_name != old
]
_registered = []

if pattern_loader.get_regex_groups() is not None:
Expand Down