lir.transform.csv_writer module

class lir.transform.csv_writer.CsvWriter(path: Path | str, include_batch_number: bool = True, include_fields: list[str] | None = None, exclude_fields: list[str] | None = None)[source]

Bases: Transformer

Implementation of a transformation step in a Pipeline that writes to CSV.

This might be used to obtain temporary or intermediate results for logging or debugging purposes.

Parameters:
  • path (Path) – Filesystem path used by this operation.

  • include_batch_number (bool) – The batch number is the sequence number of the call to apply(). Iff include_batch, this value is included as a column in the CSV file (default: True).

  • include_fields (list[str] | None) – Fields to be included, or include all fields if not specified.

  • exclude_fields (list[str] | None) – Optional list of fields to be excluded.

apply(instances: DataType) DataType[source]

Write numpy feature vector to CSV output file.

Parameters:

instances (InstanceData) – Input instances to be processed by this method.

Returns:

FeatureData object parsed from the source.

Return type:

InstanceData

fit_apply(instances: DataType) DataType[source]

Provide required fit_apply() and return all instances.

Since the CsvWriter is implemented as a step (Transformer) in the pipeline, it should support the fit_apply method which is called on all transformers of the pipeline.

This fit_apply method is typically called during training, and output is supposed to be generated for the test set only, so no output is generated at this stage. We also don’t need to actually fit or transform anything, so we simply return the instances (as is).

Parameters:

instances (InstanceDataType) – Input instances to be processed by this method.

Returns:

Instance data object produced by this operation.

Return type:

InstanceDataType