maxframe.liteframe.LiteFrame.transform_chunk#
- LiteFrame.transform_chunk(func, *, input_frame_type='pandas', dtypes=None, skip_infer=False, args=(), **kwargs)#
Apply func per execution block (chunk). Output must have same row count.
Unlike
apply_chunk, the output row count must match the input (transform semantics). The function receives a DataFrame chunk and must return a DataFrame with the same number of rows.- Parameters:
func (callable or callable class) –
Function taking a DataFrame chunk and returning a DataFrame with the same number of rows.
If
funcis a class, it is instantiated once per chunk andclose()(if defined) is always called at the end of the chunk.input_frame_type ({"pandas", "polars"}, default "pandas") – Frame type passed to
func.dtypes (dict or pd.Series, optional) – Expected output dtypes.
skip_infer (bool, default False) – If True, skip dtype inference.
args (tuple) – Extra positional arguments forwarded to
func.**kwargs – Extra keyword arguments forwarded to
func.
- Returns:
Lazy LiteFrame with the same row count as the input, where each value is the per-chunk transform result. Call
.execute()to materialize.- Return type:
See also
transformTransform per column or per row.
apply_chunkApply a function per execution chunk.
Examples
>>> import maxframe.liteframe as mlf >>> lf = mlf.LiteFrame({'a': [1, 2, 3], 'b': [10, 20, 30]})
Scale every column within each chunk by a constant (row count preserved):
>>> result = lf.transform_chunk(lambda df: df * 2) >>> result.execute() a b 0 2 20 1 4 40 2 6 60
Replace columns with a derived schema (still same row count):
>>> result = lf.transform_chunk( ... lambda df: df.assign(sum=df['a'] + df['b'])[['sum']], ... dtypes={'sum': int}) >>> result.execute() sum 0 11 1 22 2 33