medcat.utils.config_utils
Module Contents
Classes
Base class for protocol classes. |
Functions
Checks if the dict provided is an old style (jsonpickle) config. |
|
|
|
|
|
|
|
|
|
Attempf fix weighted_average_function. |
|
|
Attributes
- class medcat.utils.config_utils.WAFCarrier
Bases:
ProtocolBase class for protocol classes.
Protocol classes are defined as:
class Proto(Protocol): def meth(self) -> int: ...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:
class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:
class GenProto(Protocol[T]): def meth(self) -> T: ...
- property weighted_average_function: Callable[[float], int]
- Return type:
Callable[[float], int]
- medcat.utils.config_utils.logger
- medcat.utils.config_utils.is_old_type_config_dict(d)
Checks if the dict provided is an old style (jsonpickle) config.
This checks for json-pickle specific keys such as py/object and py/state. If both of those are keys somewhere within the 2 initial layers of the nested dict, it’s considered old style.
- Parameters:
d (dict) – Loaded config.
- Returns:
bool – Whether it’s an old style (jsonpickle) config.
- Return type:
bool
- medcat.utils.config_utils.fix_waf_lambda(carrier)
- Parameters:
carrier (WAFCarrier) –
- Return type:
None
- medcat.utils.config_utils.ensure_backward_compatibility(config, workers)
- Parameters:
config (pydantic.BaseModel) –
workers (Callable[[], int]) –
- Return type:
None
- medcat.utils.config_utils.get_and_del_weighted_average_from_config(config)
- Parameters:
config (pydantic.BaseModel) –
- Return type:
Optional[Callable[[int], float]]
- medcat.utils.config_utils.weighted_average(step, factor)
- Parameters:
step (int) –
factor (float) –
- Return type:
float
- medcat.utils.config_utils.default_weighted_average(step)
- Parameters:
step (int) –
- Return type:
float
- medcat.utils.config_utils.attempt_fix_weighted_average_function(waf)
Attempf fix weighted_average_function.
When saving a model (dill.dump) in older python versions (3.10 and before) and then loading it back up with newer versions of python (3.11 and later) there can be an issue with loading config.linking.weighted_average_function. The value attributed to this is generally a functools.partial. And it loads just fine, but cannot subsequently be called.
This method fixes the issue if the default function is used. It retains the arguments and keyword arguments of the original `partial.
What this method does is recreate the partial function based on the arguments originally provided. Along with the fix, it logs a warning.
However, if a non-default method is used, we are unable to fix it. That is because we do not know which method may have been used. In that case, a warning is logged.
- Parameters:
waf (Callable[[int], float]) – The weighted average function.
- Returns:
Callable[[int], float] – The (potentially) fixed function.
- Return type:
Callable[[int], float]
- medcat.utils.config_utils._fix_waf(waf)