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

Method map_overlap

dask/dataframe/dask_expr/_collection.py:1138–1292  ·  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

1136
1137 @insert_meta_param_description(pad=12)
1138 def map_overlap(
1139 self,
1140 func,
1141 before,
1142 after,
1143 *args,
1144 meta=no_default,
1145 enforce_metadata=True,
1146 transform_divisions=True,
1147 clear_divisions=False,
1148 align_dataframes=False,
1149 **kwargs,
1150 ):
1151 """Apply a function to each partition, sharing rows with adjacent partitions.
1152
1153 This can be useful for implementing windowing functions such as
1154 ``df.rolling(...).mean()`` or ``df.diff()``.
1155
1156 Parameters
1157 ----------
1158 func : function
1159 Function applied to each partition.
1160 before : int, timedelta or string timedelta
1161 The rows to prepend to partition ``i`` from the end of
1162 partition ``i - 1``.
1163 after : int, timedelta or string timedelta
1164 The rows to append to partition ``i`` from the beginning
1165 of partition ``i + 1``.
1166 args, kwargs :
1167 Positional and keyword arguments to pass to the function.
1168 Positional arguments are computed on a per-partition basis, while
1169 keyword arguments are shared across all partitions. The partition
1170 itself will be the first positional argument, with all other
1171 arguments passed *after*. Arguments can be ``Scalar``, ``Delayed``,
1172 or regular Python objects. DataFrame-like args (both dask and
1173 pandas) will be repartitioned to align (if necessary) before
1174 applying the function; see ``align_dataframes`` to control this
1175 behavior.
1176 enforce_metadata : bool, default True
1177 Whether to enforce at runtime that the structure of the DataFrame
1178 produced by ``func`` actually matches the structure of ``meta``.
1179 This will rename and reorder columns for each partition,
1180 and will raise an error if this doesn't work,
1181 but it won't raise if dtypes don't match.
1182 transform_divisions : bool, default True
1183 Whether to apply the function onto the divisions and apply those
1184 transformed divisions to the output.
1185 align_dataframes : bool, default True
1186 Whether to repartition DataFrame- or Series-like args
1187 (both dask and pandas) so their divisions align before applying
1188 the function. This requires all inputs to have known divisions.
1189 Single-partition inputs will be split into multiple partitions.
1190
1191 If False, all inputs must have either the same number of partitions
1192 or a single partition. Single-partition inputs will be broadcast to
1193 every partition of multi-partition inputs.
1194 $META
1195

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