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

Method map_overlap

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

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

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