pymargins.register_adapter¶
- pymargins.register_adapter(adapter_class, *, predicate=None, hint_modules=None, hint_names=None, description=None)¶
Register an adapter class for auto-detection.
This is the public hook for third-party packages (or user code) that want to support a new modelling framework without modifying pymargins core. Registered adapters are checked before the built-in hardcoded dispatch, so they can override default behaviour when necessary.
- Parameters:
adapter_class (type) – A concrete subclass of pymargins.ModelAdapter.
predicate (callable, optional) – A function
predicate(model) -> boolthat returnsTruewhenadapter_classcan wrap the supplied fitted model. If not provided,hint_modulesandhint_namesare used to build a default predicate that inspectstype(model).__module__andtype(model).__name__.hint_modules (list[str], optional) – Module-name prefixes used for error suggestions (e.g.
["statsmodels."]).hint_names (list[str], optional) – Class-name substrings used for error suggestions (e.g.
["GLM"]).description (str, optional) – Human-readable description shown in “Did you mean …?” error messages.
Examples
>>> from pymargins import register_adapter, ModelAdapter >>> class MyAdapter(ModelAdapter): ... pass >>> register_adapter( ... MyAdapter, ... predicate=lambda m: type(m).__module__.startswith("mypackage."), ... hint_modules=["mypackage."], ... hint_names=["MyModel"], ... description="mypackage MyModel", ... )
Notes
Order matters: adapters are checked in registration order. Register more-specific predicates before broader ones.