Your cart is currently empty!
Windowell Expressions -
class WindowellEngine: """Dynamic window function processor"""
def test_window_composition(self): w1 = WindowellBuilder().partition('product').build() w2 = WindowellBuilder().order('date').rows_between(1, 'preceding', 1, 'following').build() composed = WindowComposer.chain(w1, w2) self.assertEqual(composed.partition_by, ['product']) self.assertEqual(composed.order_by, ['date'])
def range_between(self, start: int, end: int): self.frame = WindowFrame( start=(start, FrameBound.PRECEDING), end=(end, FrameBound.FOLLOWING), frame_type="range" ) return self windowell expressions
def define_window(self, name: str, expression: WindowellExpression): """Register a named window template""" self.window_registry[name] = expression return self
def resolve_window(self, window_spec: str | WindowellExpression) -> WindowellExpression: """Resolve window reference with optional overrides""" if isinstance(window_spec, str): base = self.window_registry.get(window_spec) if not base: raise ValueError(f"Undefined window: window_spec") return base return window_spec 'following').build() composed = WindowComposer.chain(w1
def _apply_frame(self, df: pd.DataFrame, window: WindowellExpression) -> pd.DataFrame: """Apply frame boundaries (simplified implementation)""" # Real implementation would handle ROWS BETWEEN X PRECEDING AND Y FOLLOWING frame = window.frame if frame.frame_type == "rows" and frame.start[1] == FrameBound.PRECEDING: # Rolling window logic return df.assign( _row_num=np.arange(len(df)), _window_start=lambda x: x._row_num - frame.start[0] ) return df class WindowellBuilder: """Fluent API for building window expressions"""
@staticmethod def overlay(window1: WindowellExpression, window2: WindowellExpression): """Overlay windows: combine frame definitions""" return WindowellExpression( partition_by=window1.partition_by or window2.partition_by, order_by=window1.order_by or window2.order_by, frame=window2.frame if window2.frame else window1.frame ) class DynamicBoundary: """Compute frame boundaries dynamically from data""" def __init__(self, expression: Callable[[pd.DataFrame], int]): self.expression = expression ['date']) def range_between(self
def __init__(self): self.partition_by = [] self.order_by = [] self.frame = None