Skip to content

Commit

Permalink
Fix duplicate init ResolverSpec registration warning in has_patterns (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie256 authored Oct 30, 2023
1 parent 0b7589b commit 68d25bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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

0 comments on commit 68d25bb

Please sign in to comment.