Base class for Expr-backed Collections
| 335 | |
| 336 | |
| 337 | class FrameBase(DaskMethodsMixin): |
| 338 | """Base class for Expr-backed Collections""" |
| 339 | |
| 340 | __dask_scheduler__ = staticmethod( |
| 341 | named_schedulers.get("threads", named_schedulers["sync"]) |
| 342 | ) |
| 343 | __dask_optimize__ = staticmethod(lambda dsk, keys, **kwargs: dsk) |
| 344 | |
| 345 | def __init__(self, expr): |
| 346 | global _WARN_ANNOTATIONS |
| 347 | if _WARN_ANNOTATIONS and (annot := get_annotations()): |
| 348 | _WARN_ANNOTATIONS = False |
| 349 | warnings.warn( |
| 350 | f"Dask annotations {annot} detected. Annotations will be ignored when using query-planning." |
| 351 | ) |
| 352 | self._expr = expr |
| 353 | |
| 354 | @property |
| 355 | def expr(self) -> expr.Expr: |
| 356 | return self._expr |
| 357 | |
| 358 | @property |
| 359 | def _meta(self): |
| 360 | return self.expr._meta |
| 361 | |
| 362 | @functools.cached_property |
| 363 | def _meta_nonempty(self): |
| 364 | return meta_nonempty(self._meta) |
| 365 | |
| 366 | @property |
| 367 | def divisions(self): |
| 368 | """ |
| 369 | Tuple of ``npartitions + 1`` values, in ascending order, marking the |
| 370 | lower/upper bounds of each partition's index. Divisions allow Dask |
| 371 | to know which partition will contain a given value, significantly |
| 372 | speeding up operations like `loc`, `merge`, and `groupby` by not |
| 373 | having to search the full dataset. |
| 374 | |
| 375 | Example: for ``divisions = (0, 10, 50, 100)``, there are three partitions, |
| 376 | where the index in each partition contains values [0, 10), [10, 50), |
| 377 | and [50, 100], respectively. Dask therefore knows ``df.loc[45]`` |
| 378 | will be in the second partition. |
| 379 | |
| 380 | When every item in ``divisions`` is ``None``, the divisions are unknown. |
| 381 | Most operations can still be performed, but some will be much slower, |
| 382 | and a few may fail. |
| 383 | |
| 384 | It is not supported to set ``divisions`` directly. Instead, use ``set_index``, |
| 385 | which sorts and splits the data as needed. |
| 386 | See https://docs.dask.org/en/latest/dataframe-design.html#partitions. |
| 387 | """ |
| 388 | return self.expr.divisions |
| 389 | |
| 390 | @property |
| 391 | def npartitions(self): |
| 392 | """Return number of partitions""" |
| 393 | return self.expr.npartitions |
| 394 |