Base class for Expr-backed Collections
| 302 | |
| 303 | |
| 304 | class FrameBase(DaskMethodsMixin): |
| 305 | """Base class for Expr-backed Collections""" |
| 306 | |
| 307 | __dask_scheduler__ = staticmethod( |
| 308 | named_schedulers.get("threads", named_schedulers["sync"]) |
| 309 | ) |
| 310 | __dask_optimize__ = staticmethod(lambda dsk, keys, **kwargs: dsk) |
| 311 | |
| 312 | def __init__(self, expr): |
| 313 | global _WARN_ANNOTATIONS |
| 314 | if _WARN_ANNOTATIONS and (annot := get_annotations()): |
| 315 | _WARN_ANNOTATIONS = False |
| 316 | warnings.warn( |
| 317 | f"Dask annotations {annot} detected. Annotations will be ignored when using query-planning." |
| 318 | ) |
| 319 | self._expr = expr |
| 320 | |
| 321 | @property |
| 322 | def expr(self) -> expr.Expr: |
| 323 | return self._expr |
| 324 | |
| 325 | @property |
| 326 | def _meta(self): |
| 327 | return self.expr._meta |
| 328 | |
| 329 | @functools.cached_property |
| 330 | def _meta_nonempty(self): |
| 331 | return meta_nonempty(self._meta) |
| 332 | |
| 333 | @property |
| 334 | def divisions(self): |
| 335 | """ |
| 336 | Tuple of ``npartitions + 1`` values, in ascending order, marking the |
| 337 | lower/upper bounds of each partition's index. Divisions allow Dask |
| 338 | to know which partition will contain a given value, significantly |
| 339 | speeding up operations like `loc`, `merge`, and `groupby` by not |
| 340 | having to search the full dataset. |
| 341 | |
| 342 | Example: for ``divisions = (0, 10, 50, 100)``, there are three partitions, |
| 343 | where the index in each partition contains values [0, 10), [10, 50), |
| 344 | and [50, 100], respectively. Dask therefore knows ``df.loc[45]`` |
| 345 | will be in the second partition. |
| 346 | |
| 347 | When every item in ``divisions`` is ``None``, the divisions are unknown. |
| 348 | Most operations can still be performed, but some will be much slower, |
| 349 | and a few may fail. |
| 350 | |
| 351 | It is not supported to set ``divisions`` directly. Instead, use ``set_index``, |
| 352 | which sorts and splits the data as needed. |
| 353 | See https://docs.dask.org/en/latest/dataframe-design.html#partitions. |
| 354 | """ |
| 355 | return self.expr.divisions |
| 356 | |
| 357 | @property |
| 358 | def npartitions(self): |
| 359 | """Return number of partitions""" |
| 360 | return self.expr.npartitions |
| 361 |