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

Method compute_current_divisions

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

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

Calls 3

new_collectionFunction · 0.90
_compute_partition_statsFunction · 0.85
anyFunction · 0.85