Take the first `n` rows of every partition Typically used after `Partitions(..., [0])` to take the first `n` rows of an entire collection.
| 2611 | |
| 2612 | |
| 2613 | class BlockwiseHead(Head, Blockwise): |
| 2614 | """Take the first `n` rows of every partition |
| 2615 | |
| 2616 | Typically used after `Partitions(..., [0])` to take |
| 2617 | the first `n` rows of an entire collection. |
| 2618 | """ |
| 2619 | |
| 2620 | _parameters = ["frame", "n", "npartitions", "safe"] |
| 2621 | _preserves_partitioning_information = True |
| 2622 | |
| 2623 | def _simplify_down(self): |
| 2624 | return |
| 2625 | |
| 2626 | def _simplify_up(self, parent, dependents): |
| 2627 | return |
| 2628 | |
| 2629 | @functools.cached_property |
| 2630 | def npartitions(self): |
| 2631 | return len(self._divisions()) - 1 |
| 2632 | |
| 2633 | def _divisions(self): |
| 2634 | return self.frame.divisions[: len(self._partitions) + 1] |
| 2635 | |
| 2636 | def _task(self, name: Key, index: int) -> Task: |
| 2637 | if self.safe: |
| 2638 | op = safe_head |
| 2639 | else: |
| 2640 | op = M.head |
| 2641 | return Task(name, op, TaskRef((self.frame._name, index)), self.n) |
| 2642 | |
| 2643 | |
| 2644 | class BlockwiseHeadIndex(BlockwiseHead): |