| 1046 | |
| 1047 | |
| 1048 | class Len(Reduction): |
| 1049 | reduction_chunk = staticmethod(len) |
| 1050 | reduction_aggregate = sum |
| 1051 | |
| 1052 | def _simplify_down(self): |
| 1053 | from dask.dataframe.dask_expr.io.io import IO |
| 1054 | |
| 1055 | # We introduce Index nodes sometimes. We special case around them. |
| 1056 | if isinstance(self.frame, Index) and self.frame.frame._is_length_preserving: |
| 1057 | return Len(self.frame.frame) |
| 1058 | |
| 1059 | # Pass through Elemwises, unless we just introduced an Index |
| 1060 | if self.frame._is_length_preserving and not isinstance(self.frame, Index): |
| 1061 | child = max(self.frame.dependencies(), key=lambda expr: expr.npartitions) |
| 1062 | return Len(child) |
| 1063 | |
| 1064 | # Let the child handle it. They often know best |
| 1065 | if isinstance(self.frame, IO): |
| 1066 | return self |
| 1067 | |
| 1068 | if isinstance(self.frame, Concat) and self.frame.operand("axis") == 0: |
| 1069 | return sum(Len(obj) for obj in self.frame.dependencies()) |
| 1070 | |
| 1071 | # Drop all of the columns, just pass through the index |
| 1072 | if self.frame.ndim == 2 and len(self.frame.columns): |
| 1073 | return Len(self.frame.index) |
| 1074 | |
| 1075 | def _simplify_up(self, parent, dependents): |
| 1076 | return |
| 1077 | |
| 1078 | |
| 1079 | class Size(Reduction): |
no outgoing calls