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

class lir.config.transform.NumpyWrappingConfigParser(module_parser: ConfigParser)[source]

Bases: ConfigParser

Wrap a Transformer to add a header to FeatureData.

Parameters:

module_parser (ConfigParser) – Parser used to create the wrapped transformer.

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

Parse the provided header configuration.

Parameters:
  • config (ContextAwareDict) – Configuration possibly containing header and module fields.

  • output_dir (Path) – Output directory passed to the wrapped parser.

Returns:

Wrapped transformer that preserves numpy headers.

Return type:

Transformer

reference() str[source]

Return the full name of the module_parser class argument.

Returns:

Reference string for the wrapped parser.

Return type:

str

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