Skip to content

Commit

Permalink
Improve error messaging for variable fitting (#347)
Browse files Browse the repository at this point in the history
* Improve error messaging for variable fitting

* Fix erroneous mypy error
  • Loading branch information
qubixes authored Dec 9, 2024
1 parent e7ade01 commit ab14341
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion metasyn/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import warnings
from abc import ABC
from inspect import signature
from typing import TYPE_CHECKING, Any, List, Optional, Type, Union

try:
Expand Down Expand Up @@ -247,7 +248,16 @@ def create(self, var_spec: Union[VarSpec, VarSpecAccess]) -> BaseDistribution:
dist_class = self.find_distribution(
dist_spec.implements, var_spec.var_type,
privacy=BasicPrivacy(), unique=unique)
return dist_class(**dist_spec.parameters)
try:
return dist_class(**dist_spec.parameters)
except TypeError as err:
dist_param = set(signature(dist_class.__init__).parameters) - {"self"} # type: ignore
if "args" in dist_param or "kwargs" in dist_param:
raise err
unknown_param = set(dist_spec.parameters) - dist_param # type: ignore
if len(unknown_param) > 0:
raise TypeError(f"Unknown parameters {unknown_param} for variable {var_spec.name}.")
raise err

def _find_best_fit(self, series: pl.Series, var_type: str,
unique: Optional[bool],
Expand Down

0 comments on commit ab14341

Please sign in to comment.