MCPcopy Create free account
hub / github.com/dask/dask / Len

Class Len

dask/dataframe/dask_expr/_reductions.py:1048–1076  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1046
1047
1048class 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
1079class Size(Reduction):

Callers 9

__len__Method · 0.90
value_countsMethod · 0.90
test_parquet_lenFunction · 0.90
test_parquet_len_filterFunction · 0.90
test_lenFunction · 0.90
test_concat_indexFunction · 0.90
_simplify_downMethod · 0.85
_simplify_downMethod · 0.85

Calls

no outgoing calls

Tested by 5

test_parquet_lenFunction · 0.72
test_parquet_len_filterFunction · 0.72
test_lenFunction · 0.72
test_concat_indexFunction · 0.72