Skip to content

base

base ¤

Base class and architecture guidelines for ts-shape.

ts-shape uses two complementary patterns for data processing. Choose the right one based on the complexity of the operation:

Stateless classmethods — use when:

  • The operation is a single, self-contained transformation (filter, calculate, convert, aggregate).
  • There is no shared configuration between methods.
  • The result depends only on the inputs (pure function).
  • Examples: IntegerCalc, StringFilter, NumericStatistics, DateTimeFilter, LambdaProcessor.

Stateful instance classes — use when:

  • Multiple related methods share configuration (column names, signal UUIDs, thresholds, tolerances).
  • The constructor validates or preprocesses data once for many operations (e.g. sorting, filtering to a specific UUID).
  • The domain workflow has a natural setup phase before analysis (e.g. compute control limits, then apply SPC rules).
  • Examples: DataHarmonizer, OutlierDetectionEvents, MachineStateEvents, OEECalculator, all event classes.

FeaturePipeline — use when chaining multiple steps:

  • Combines both patterns via add_step() (classmethods) and add_instance_step() (instance classes).
  • Supports $prev / $input sentinels for multi-DataFrame wiring.
  • Provides logging, timing, and intermediate result capture.
  • See ts_shape.features.segment_analysis.feature_pipeline.

Base ¤

Base(dataframe: DataFrame, column_name: str = 'systime')

Initializes the Base with a DataFrame, detects time columns, converts them to datetime, and sorts the DataFrame by the specified column (or the detected time column if applicable).

Parameters:

Name Type Description Default
dataframe DataFrame

The DataFrame to be processed.

required
column_name str

The column to sort by. Default is 'systime'. If the column is not found or is not a time column, the class will attempt to detect other time columns.

'systime'

Raises:

Type Description
TypeError

If dataframe is not a pandas DataFrame.

get_dataframe ¤

get_dataframe() -> pd.DataFrame

Returns the processed DataFrame.