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

Method compute_current_divisions

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

2347 return ~self.notnull()
2348
2349 def compute_current_divisions(self, col=None, set_divisions: bool = False):
2350 """Compute the current divisions of the DataFrame.
2351
2352 This method triggers immediate computation. If you find yourself running this command
2353 repeatedly for the same dataframe, we recommend storing the result
2354 so you don't have to rerun it.
2355
2356 If the column or index values overlap between partitions, raises ``ValueError``.
2357 To prevent this, make sure the data are sorted by the column or index.
2358
2359 Parameters
2360 ----------
2361 col : string, optional
2362 Calculate the divisions for a non-index column by passing in the name of the column.
2363 If col is not specified, the index will be used to calculate divisions.
2364 In this case, if the divisions are already known, they will be returned
2365 immediately without computing.
2366 set_divisions : bool, default False
2367 Whether to set the computed divisions into the DataFrame. If False, the divisions
2368 of the DataFrame are unchanged.
2369
2370 Examples
2371 --------
2372 >>> import dask
2373 >>> ddf = dask.datasets.timeseries(start="2021-01-01", end="2021-01-07", freq="1h").clear_divisions()
2374 >>> divisions = ddf.compute_current_divisions()
2375 >>> print(divisions) # doctest: +NORMALIZE_WHITESPACE
2376 (Timestamp('2021-01-01 00:00:00'),
2377 Timestamp('2021-01-02 00:00:00'),
2378 Timestamp('2021-01-03 00:00:00'),
2379 Timestamp('2021-01-04 00:00:00'),
2380 Timestamp('2021-01-05 00:00:00'),
2381 Timestamp('2021-01-06 00:00:00'),
2382 Timestamp('2021-01-06 23:00:00'))
2383
2384 >>> ddf = ddf.reset_index().clear_divisions()
2385 >>> divisions = ddf.compute_current_divisions("timestamp")
2386 >>> print(divisions) # doctest: +NORMALIZE_WHITESPACE
2387 (Timestamp('2021-01-01 00:00:00'),
2388 Timestamp('2021-01-02 00:00:00'),
2389 Timestamp('2021-01-03 00:00:00'),
2390 Timestamp('2021-01-04 00:00:00'),
2391 Timestamp('2021-01-05 00:00:00'),
2392 Timestamp('2021-01-06 00:00:00'),
2393 Timestamp('2021-01-06 23:00:00'))
2394
2395 >>> ddf = ddf.set_index("timestamp", divisions=divisions, sorted=True)
2396 """
2397 if col is None and self.known_divisions:
2398 if set_divisions:
2399 return self
2400 return self.divisions
2401
2402 if col is not None and set_divisions:
2403 raise NotImplementedError(
2404 "Can't set divisions of non-index, call set_index instead."
2405 )
2406

Calls 3

new_collectionFunction · 0.90
_compute_partition_statsFunction · 0.85
anyFunction · 0.85