Skip to content

mostlyright.transforms

Phase 3.5 — Transforms DSL + preprocessing primitives.

Phase 3.5 v0.1.0 scope: the baseline-quant feature-engineering surface (lag/diff/rolling/calendar/cross-features + clip_outliers + iem_crosscheck). Removes the “Sprint 0.5+ preprocessing” defer.

Surface:

  • lag(df, column, periods)() — shift a column by N rows.
  • diff(df, column, periods=1)() — first-difference of a column.
  • diff2(df, column)() — second-difference.
  • rolling(df, column, window, fn)() — windowed reduction.
  • calendar_features(df, date_column)() — cyclical month/dow/hour.
  • spread(df, col_a, col_b)() — pairwise diff.
  • wind_chill(temp_f, wind_mph)() — NWS wind chill.
  • heat_index(temp_f, rh_pct)() — NWS heat index.
  • clip_outliers(df, column, std=3.0)() — winsorize.
calendar_features(df, date_column)Add cyclical calendar features to df.
clip_outliers(df, column, *[, std])Winsorize: clip df[column] to mean ± std * sigma.
diff(df, column[, periods])First-difference of df[column].
diff2(df, column)Second-difference of df[column].
heat_index(temp_f, rh_pct)NWS heat index (Rothfusz regression, valid temp >= 80F).
lag(df, column[, periods])Return a Series with df[column] lagged by periods rows.
rolling(df, column, window[, fn])Apply a rolling reduction to df[column].
spread(df, col_a, col_b)Return df[col_a] - df[col_b].
wind_chill(temp_f, wind_mph)NWS wind chill formula (valid for temp <= 50F, wind > 3 mph).

mostlyright.transforms.calendar_features(df, date_column)

Section titled “mostlyright.transforms.calendar_features(df, date_column)”

Add cyclical calendar features to df.

Returns a NEW DataFrame with added columns:

  • day_of_year_sin, day_of_year_cos — cyclical year position.
  • hour_sin, hour_cos — cyclical time-of-day.
  • month_sin, month_cos — cyclical month.
  • dow_sin, dow_cos — cyclical day-of-week.

Cyclical pairs satisfy sin² + cos² ≈ 1 so a model sees the wraparound (Dec → Jan is 1 day, not 11 months apart). Property test asserts this invariant via Hypothesis (Phase 3.5 ROADMAP SC-2).

Phase 6 W2-T2: accepts pandas OR polars input; returns the same backend type the caller passed.

  • Return type: DataFrame
  • Parameters:
    • df (DataFrame)
    • date_column (str)

mostlyright.transforms.clip_outliers(df, column, , std=3.0)

Section titled “mostlyright.transforms.clip_outliers(df, column, , std=3.0)”

Winsorize: clip df[column] to mean ± std * sigma.

  • Return type: Series
  • Parameters:
    • df (DataFrame)
    • column (str)
    • std (float)

mostlyright.transforms.diff(df, column, periods=1)

Section titled “mostlyright.transforms.diff(df, column, periods=1)”

First-difference of df[column].

  • Return type: Series
  • Parameters:
    • df (DataFrame)
    • column (str)
    • periods (int)

Second-difference of df[column].

  • Return type: Series
  • Parameters:
    • df (DataFrame)
    • column (str)

mostlyright.transforms.heat_index(temp_f, rh_pct)

Section titled “mostlyright.transforms.heat_index(temp_f, rh_pct)”

NWS heat index (Rothfusz regression, valid temp >= 80F).

mostlyright.transforms.lag(df, column, periods=1)

Section titled “mostlyright.transforms.lag(df, column, periods=1)”

Return a Series with df[column] lagged by periods rows.

  • Return type: Series
  • Parameters:
    • df (DataFrame)
    • column (str)
    • periods (int)

mostlyright.transforms.rolling(df, column, window, fn=‘mean’)

Section titled “mostlyright.transforms.rolling(df, column, window, fn=‘mean’)”

Apply a rolling reduction to df[column].

  • Return type: Series
  • Parameters:

mostlyright.transforms.spread(df, col_a, col_b)

Section titled “mostlyright.transforms.spread(df, col_a, col_b)”

Return df[col_a] - df[col_b].

  • Return type: Series
  • Parameters:
    • df (DataFrame)
    • col_a (str)
    • col_b (str)

mostlyright.transforms.wind_chill(temp_f, wind_mph)

Section titled “mostlyright.transforms.wind_chill(temp_f, wind_mph)”

NWS wind chill formula (valid for temp <= 50F, wind > 3 mph).