Skip to content

Commit

Permalink
CU-8692uznvd: Move the empty-set detection and conversion from valida…
Browse files Browse the repository at this point in the history
…tor to init
  • Loading branch information
mart-r committed Oct 20, 2023
1 parent a6872e3 commit 0407008
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions medcat/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,18 +433,18 @@ class LinkingFilters(MixingConfig, BaseModel):
cuis: Set[str] = set()
cuis_exclude: Set[str] = set()

@validator("cuis", pre=True, always=True)
def convert_empty_dict_to_set(cls, value):
if isinstance(value, dict) and not value:
# is empty dict
logger.warning("Loading an old model where "
"config.linking.filters.cuis has been "
"dict to an empty dict instead of an empty "
"set. Converting the dict to a set in memory "
"as that is what is expected. Please consider "
"saving the model again.")
return set()
return value
def __init__(self, **data):
if 'cuis' in data:
cuis = data['cuis']
if isinstance(cuis, dict) and len(cuis) == 0:
logger.warning("Loading an old model where "
"config.linking.filters.cuis has been "
"dict to an empty dict instead of an empty "
"set. Converting the dict to a set in memory "
"as that is what is expected. Please consider "
"saving the model again.")
data['cuis'] = set(cuis.keys())
super().__init__(**data)

def check_filters(self, cui: str) -> bool:
"""Checks is a CUI in the filters
Expand Down

0 comments on commit 0407008

Please sign in to comment.