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

Method compute_current_divisions

dask/dataframe/dask_expr/_collection.py:2315–2386  ·  view source on GitHub ↗

Compute the current divisions of the DataFrame. This method triggers immediate computation. If you find yourself running this command repeatedly for the same dataframe, we recommend storing the result so you don't have to rerun it. If the column or index values over

(self, col=None, set_divisions: bool = False)

Source from the content-addressed store, hash-verified

2313 return ~self.notnull()
2314
2315 def compute_current_divisions(self, col=None, set_divisions: bool = False):
2316 """Compute the current divisions of the DataFrame.
2317
2318 This method triggers immediate computation. If you find yourself running this command
2319 repeatedly for the same dataframe, we recommend storing the result
2320 so you don't have to rerun it.
2321
2322 If the column or index values overlap between partitions, raises ``ValueError``.
2323 To prevent this, make sure the data are sorted by the column or index.
2324
2325 Parameters
2326 ----------
2327 col : string, optional
2328 Calculate the divisions for a non-index column by passing in the name of the column.
2329 If col is not specified, the index will be used to calculate divisions.
2330 In this case, if the divisions are already known, they will be returned
2331 immediately without computing.
2332 set_divisions : bool, default False
2333 Whether to set the computed divisions into the DataFrame. If False, the divisions
2334 of the DataFrame are unchanged.
2335
2336 Examples
2337 --------
2338 >>> import dask
2339 >>> ddf = dask.datasets.timeseries(start="2021-01-01", end="2021-01-07", freq="1h").clear_divisions()
2340 >>> divisions = ddf.compute_current_divisions()
2341 >>> print(divisions) # doctest: +NORMALIZE_WHITESPACE
2342 (Timestamp('2021-01-01 00:00:00'),
2343 Timestamp('2021-01-02 00:00:00'),
2344 Timestamp('2021-01-03 00:00:00'),
2345 Timestamp('2021-01-04 00:00:00'),
2346 Timestamp('2021-01-05 00:00:00'),
2347 Timestamp('2021-01-06 00:00:00'),
2348 Timestamp('2021-01-06 23:00:00'))
2349
2350 >>> ddf = ddf.reset_index().clear_divisions()
2351 >>> divisions = ddf.compute_current_divisions("timestamp")
2352 >>> print(divisions) # doctest: +NORMALIZE_WHITESPACE
2353 (Timestamp('2021-01-01 00:00:00'),
2354 Timestamp('2021-01-02 00:00:00'),
2355 Timestamp('2021-01-03 00:00:00'),
2356 Timestamp('2021-01-04 00:00:00'),
2357 Timestamp('2021-01-05 00:00:00'),
2358 Timestamp('2021-01-06 00:00:00'),
2359 Timestamp('2021-01-06 23:00:00'))
2360
2361 >>> ddf = ddf.set_index("timestamp", divisions=divisions, sorted=True)
2362 """
2363 if col is None and self.known_divisions:
2364 if set_divisions:
2365 return self
2366 return self.divisions
2367
2368 if col is not None and set_divisions:
2369 raise NotImplementedError(
2370 "Can't set divisions of non-index, call set_index instead."
2371 )
2372

Calls 3

new_collectionFunction · 0.90
_compute_partition_statsFunction · 0.85
anyFunction · 0.85