lir.config.transform module

class lir.config.transform.GenericTransformerConfigParser(component_class: object)[source]

Bases: ConfigParser

Parser class to help parse the defined component into its corresponding Transformer object.

Since the scikit-learn Pipeline expects a fit() and transform() method on each of the pipeline steps, the configured components should adhere to this contract and implement these methods.

The parse() function offered in this helper class, implements a branching strategy to determine which strategy is best suited to make the component compatible with the scikit-learn pipeline.

Parameters:

component_class (object) – Component class or callable to adapt to the transformer interface.

parse(config: ContextAwareDict, output_dir: Path) Transformer[source]

Prepare a configured component for use in a scikit-learn pipeline.

Parameters:
  • config (ContextAwareDict) – Constructor arguments for the component class.

  • output_dir (Path) – Unused output directory argument required by parser API.

Returns:

Component adapted to the Transformer interface.

Return type:

Transformer

lir.config.transform.parse_module(module_config: ContextAwareDict | str | None, output_dir: Path, config_context_path: list[str], default_method: str | None = None) Transformer[source]

Construct a Transformer from a string or configuration section.

If module_config is None, an Identity transformer is returned.

If module_config is a dictionary, it must contain a method field whose value is the name of an object looked up in the registry. All remaining fields are passed as initialisation arguments. If no arguments are required, the input may be given directly as the object name.

The resolved object is handled as follows:

  • If it is a subclass of ConfigParser, the class is instantiated and the result of its parse() method is returned.

  • If it defines a transform method, or is a subclass of Transformer, it is instantiated and returned.

  • If it defines a predict_proba method, it is instantiated, wrapped in EstimatorTransformer, and returned.

  • Any other callable is wrapped in FunctionTransformer and returned.

If module_config is a string, this function behaves as if a dictionary with a single field method set to that string had been provided.

Parameters:
  • module_config (ContextAwareDict | str | None) – Specification of the module.

  • output_dir (Path) – Directory where any output produced by the module is written.

  • config_context_path (list[str]) – Context path of this configuration, used for error reporting.

  • default_method (str | None, optional) – Default value for the method field if it is not provided.

Returns:

The constructed transformer instance.

Return type:

Transformer

lir.config.transform.parse_pairing_config(module_config: ContextAwareDict | str, output_dir: Path, context: list[str]) PairingMethod[source]

Parse and delegate pairing to the corresponding function for the defined pairing method.

The argument module_config defines the pairing method. If its value is a str, the registry is queried and the corresponding pairing method is returned. If its value is a dict, the pairing method is defined by the value module_config[“method”], and the registry is queried for the config parser of the corresponding pairing method. The remaining values in module_config are passed as arguments to the configuration parser of the pairing method.

If the registry cannot resolve the pairing method, an exception is raised.

Parameters:
  • module_config (ContextAwareDict | str) – Pairing method configuration.

  • output_dir (Path) – Output directory for parser calls.

  • context (list[str]) – Context used when module_config is a string.

Returns:

Parsed pairing method.

Return type:

PairingMethod