Monte Carlo Benchmarking Engine
High-performance SIMD Monte Carlo engine (AVX2/NEON) with custom memory allocators and perf logging.
 
Loading...
Searching...
No Matches
utils.py File Reference

Shared utilities for safe casting, schema enforcement, and arithmetic fallback logic. More...

Go to the source code of this file.

Namespaces

namespace  pipeline
 
namespace  pipeline.utils
 

Functions

pl.DataFrame pipeline.utils.safe_vector_cast (pl.DataFrame df, dict schema)
 Cast a Polars DataFrame to match a declared schema, handling 'NA' strings as nulls.
 
 pipeline.utils.safe_div (numerator, denominator)
 Safely performs division, handling 'NA' values and invalid input.
 
 pipeline.utils.safe_div_percent (numerator, denominator)
 Computes percentage-based division safely, with 'NA' fallback.
 

Detailed Description

Shared utilities for safe casting, schema enforcement, and arithmetic fallback logic.

Description
This module provides shared helpers for safely working with metrics data in a Polars-based pipeline. It ensures robust schema alignment and safe numerical operations, especially when working with mixed or incomplete CSV inputs.
Included Utilities
  • safe_vector_cast: Vectorized, schema-aware casting for Polars DataFrames
  • safe_div: Division with fallback for invalid or "NA" input
  • safe_div_percent: Percentage-style division with "NA" guard
Usage
from utils import safe_vector_cast, safe_div, safe_div_percent
Design Notes
  • Schema mismatches are surfaced with detailed debug output
  • "NA" strings are treated as nulls when allow_na is True
  • Division errors (e.g., zero division, bad input) are handled gracefully

Definition in file utils.py.