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

TypeError in new version 1.11.1 #113

Closed
vnmabus opened this issue Feb 23, 2024 · 6 comments
Closed

TypeError in new version 1.11.1 #113

vnmabus opened this issue Feb 23, 2024 · 6 comments

Comments

@vnmabus
Copy link

vnmabus commented Feb 23, 2024

I am having problems in my project with the new version 1.11.1.

In particular it seems that the following multimethod:

https://github.com/GAA-UAM/scikit-fda/blob/b43718a92bd7189e3c821913c6de447aaa25b291/skfda/misc/metrics/_utils.py#L140

is causing some kind of error due to generics:

File .../skfda/misc/metrics/_utils.py:183, in PairwiseMetric.__call__(self, elem1, elem2)
    177 def __call__(
    178     self,
    179     elem1: _MapAcceptableT,
    180     elem2: Optional[_MapAcceptableT] = None,
    181 ) -> NDArrayFloat:
    182     """Evaluate the pairwise metric."""
--> 183     optimized = pairwise_metric_optimization(self.metric, elem1, elem2)
    185     return (
    186         _pairwise_symmetric(
    187             self.metric,  # type: ignore[arg-type]
   (...)
    192         else optimized
    193     )

File .../site-packages/multimethod/__init__.py:421, in multidispatch.__call__(self, *args, **kwargs)
    419 """Resolve and dispatch to best method."""
    420 params = self.signature.bind(*args, **kwargs).args if (kwargs and self.signature) else args
--> 421 func = self.dispatch(*params)
    422 return func(*args, **kwargs)

File .../site-packages/multimethod/__init__.py:354, in multimethod.dispatch(self, *args)
    352 def dispatch(self, *args) -> Callable:
    353     types = tuple(map(type, args))
--> 354     if not any(map(issubclass, types, self.generics)):
    355         return self[types]
    356     matches = {key for key in list(self) if isinstance(key, signature) and key.instances(*args)}

File .../typing.py:1308, in _BaseGenericAlias.__subclasscheck__(self, cls)
   1307 def __subclasscheck__(self, cls):
-> 1308     raise TypeError("Subscripted generics cannot be used with"
   1309                     " class and instance checks")

TypeError: Subscripted generics cannot be used with class and instance checks

I tried unsuccessfully to create a minimum example showing the error, but as the changes in the last version are few, maybe you do not need it to locate the error.

@coady
Copy link
Owner

coady commented Feb 25, 2024

4e22af5 might be related. In addition to that, you could try logging:

  • the types at runtimes
  • the registered types in .generics at import time - one of them must be a generic

@ccaballeroh
Copy link

I also had this same error a few days ago indirectly through Pandera. It got solved pinning the version of multimethod to 1.11. This is mentioned over here unionai-oss/pandera#1500.

Maybe 8346c76 is related? I have spent a fair amount of time checking the code, but I'm over my head here.

@vnmabus
Copy link
Author

vnmabus commented Feb 26, 2024

4e22af5 might be related. In addition to that, you could try logging:

* the types at runtimes

* the registered types in `.generics` at import time - one of them must be a generic

It seems that self.generics is [(skfda.typing._metric.Metric[~Original], skfda.misc.metrics._utils.NormInducedMetric[typing.Union[numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]], skfda.representation._functional_data.FData]], typing.Generic[~Original, ~Transformed])].

The error appears in _BaseGenericAlias.__subclasscheck__ with parameters self=skfda.typing._metric.Metric[~Original], cls=<class 'skfda.misc.metrics._lp_distances.LpDistance'>.

@coady
Copy link
Owner

coady commented Feb 26, 2024

The error appears in _BaseGenericAlias.__subclasscheck__ with parameters self=skfda.typing._metric.Metric[~Original], cls=<class 'skfda.misc.metrics._lp_distances.LpDistance'>.

Thanks, I'm confident this is fixed in main (4e22af5 and later). I'll add a regression test that's as close to Metric as possible.

If anyone on this thread can test theirs against main, that would be appreciated.

coady added a commit that referenced this issue Feb 27, 2024
@coady
Copy link
Owner

coady commented Feb 28, 2024

Released v1.11.2.

@coady
Copy link
Owner

coady commented Mar 8, 2024

Fixed in v1.11.2.

@coady coady closed this as completed Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants