Take the first `n` rows of every partition Typically used after `Partitions(..., [0])` to take the first `n` rows of an entire collection.
| 2630 | |
| 2631 | |
| 2632 | class BlockwiseHead(Head, Blockwise): |
| 2633 | """Take the first `n` rows of every partition |
| 2634 | |
| 2635 | Typically used after `Partitions(..., [0])` to take |
| 2636 | the first `n` rows of an entire collection. |
| 2637 | """ |
| 2638 | |
| 2639 | _parameters = ["frame", "n", "npartitions", "safe"] |
| 2640 | _preserves_partitioning_information = True |
| 2641 | |
| 2642 | def _simplify_down(self): |
| 2643 | return |
| 2644 | |
| 2645 | def _simplify_up(self, parent, dependents): |
| 2646 | return |
| 2647 | |
| 2648 | @functools.cached_property |
| 2649 | def npartitions(self): |
| 2650 | return len(self._divisions()) - 1 |
| 2651 | |
| 2652 | def _divisions(self): |
| 2653 | return self.frame.divisions[: len(self._partitions) + 1] |
| 2654 | |
| 2655 | def _task(self, name: Key, index: int) -> Task: |
| 2656 | if self.safe: |
| 2657 | op = safe_head |
| 2658 | else: |
| 2659 | op = M.head |
| 2660 | return Task(name, op, TaskRef((self.frame._name, index)), self.n) |
| 2661 | |
| 2662 | |
| 2663 | class BlockwiseHeadIndex(BlockwiseHead): |