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

Method compute_current_divisions

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

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

Calls 3

new_collectionFunction · 0.90
_compute_partition_statsFunction · 0.85
anyFunction · 0.85