MCPcopy Create free account
hub / github.com/dask/dask / map_overlap

Method map_overlap

dask/dataframe/dask_expr/_collection.py:1172–1326  ·  view source on GitHub ↗

Apply a function to each partition, sharing rows with adjacent partitions. This can be useful for implementing windowing functions such as ``df.rolling(...).mean()`` or ``df.diff()``. Parameters ---------- func : function Function applied to each

(
        self,
        func,
        before,
        after,
        *args,
        meta=no_default,
        enforce_metadata=True,
        transform_divisions=True,
        clear_divisions=False,
        align_dataframes=False,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

1170
1171 @insert_meta_param_description(pad=12)
1172 def map_overlap(
1173 self,
1174 func,
1175 before,
1176 after,
1177 *args,
1178 meta=no_default,
1179 enforce_metadata=True,
1180 transform_divisions=True,
1181 clear_divisions=False,
1182 align_dataframes=False,
1183 **kwargs,
1184 ):
1185 """Apply a function to each partition, sharing rows with adjacent partitions.
1186
1187 This can be useful for implementing windowing functions such as
1188 ``df.rolling(...).mean()`` or ``df.diff()``.
1189
1190 Parameters
1191 ----------
1192 func : function
1193 Function applied to each partition.
1194 before : int, timedelta or string timedelta
1195 The rows to prepend to partition ``i`` from the end of
1196 partition ``i - 1``.
1197 after : int, timedelta or string timedelta
1198 The rows to append to partition ``i`` from the beginning
1199 of partition ``i + 1``.
1200 args, kwargs :
1201 Positional and keyword arguments to pass to the function.
1202 Positional arguments are computed on a per-partition basis, while
1203 keyword arguments are shared across all partitions. The partition
1204 itself will be the first positional argument, with all other
1205 arguments passed *after*. Arguments can be ``Scalar``, ``Delayed``,
1206 or regular Python objects. DataFrame-like args (both dask and
1207 pandas) will be repartitioned to align (if necessary) before
1208 applying the function; see ``align_dataframes`` to control this
1209 behavior.
1210 enforce_metadata : bool, default True
1211 Whether to enforce at runtime that the structure of the DataFrame
1212 produced by ``func`` actually matches the structure of ``meta``.
1213 This will rename and reorder columns for each partition,
1214 and will raise an error if this doesn't work,
1215 but it won't raise if dtypes don't match.
1216 transform_divisions : bool, default True
1217 Whether to apply the function onto the divisions and apply those
1218 transformed divisions to the output.
1219 align_dataframes : bool, default True
1220 Whether to repartition DataFrame- or Series-like args
1221 (both dask and pandas) so their divisions align before applying
1222 the function. This requires all inputs to have known divisions.
1223 Single-partition inputs will be split into multiple partitions.
1224
1225 If False, all inputs must have either the same number of partitions
1226 or a single partition. Single-partition inputs will be broadcast to
1227 every partition of multi-partition inputs.
1228 $META
1229

Callers 11

test_map_overlapFunction · 0.45
test_map_overlap_raisesFunction · 0.45
test_map_overlap_errorsFunction · 0.45
test_map_overlapFunction · 0.45
test_map_overlap_namesFunction · 0.45
test_map_overlap_errorsFunction · 0.45
test_time_rollingFunction · 0.45

Calls 1

map_overlapFunction · 0.70

Tested by 11

test_map_overlapFunction · 0.36
test_map_overlap_raisesFunction · 0.36
test_map_overlap_errorsFunction · 0.36
test_map_overlapFunction · 0.36
test_map_overlap_namesFunction · 0.36
test_map_overlap_errorsFunction · 0.36
test_time_rollingFunction · 0.36