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

Method _lower

dask/dataframe/dask_expr/_reductions.py:172–285  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

170 return 1
171
172 def _lower(self):
173 from dask.dataframe.dask_expr._repartition import Repartition
174 from dask.dataframe.dask_expr._shuffle import (
175 RearrangeByColumn,
176 SetIndexBlockwise,
177 SortValues,
178 )
179
180 if is_index_like(self.frame._meta):
181 columns = [
182 (
183 self.frame._meta.name
184 if self.frame._meta.name is not None
185 else "__index__"
186 )
187 ]
188 elif is_series_like(self.frame._meta):
189 columns = [
190 (
191 self.frame._meta.name
192 if self.frame._meta.name is not None
193 else "__series__"
194 )
195 ]
196 else:
197 columns = self.frame.columns
198
199 # Find what columns we are shuffling by
200 split_by = self.split_by or columns
201 if not isinstance(split_by, (list, tuple)):
202 split_by = [split_by]
203 split_by_index = bool(set(split_by) - set(columns))
204
205 # Make sure we have dataframe-like data to shuffle
206 if split_by_index:
207 if self.frame.ndim == 1:
208 chunked = ResetIndex(self.frame, drop=False, name=self.frame.name)
209 else:
210 chunked = ResetIndex(self.frame, drop=False)
211 if split_by == [None]:
212 split_by = ["index"]
213 elif is_index_like(self.frame._meta) or is_series_like(self.frame._meta):
214 chunked = ToFrame(self.frame, name=columns[0])
215 else:
216 chunked = self.frame
217
218 # Map Tuple[str] column names to str before the shuffle
219 map_columns = {col: str(col) for col in chunked.columns if col != str(col)}
220 unmap_columns = {v: k for k, v in map_columns.items()}
221 if map_columns:
222 chunked = RenameFrame(chunked, map_columns)
223 split_by = [map_columns.get(c, c) for c in split_by]
224
225 # Sort or shuffle
226 split_every = getattr(self, "split_every", 0) or chunked.npartitions
227 ignore_index = getattr(self, "ignore_index", True)
228 if self.shuffle_by_index is not None:
229 ignore_index = not self.shuffle_by_index

Callers

nothing calls this directly

Calls 15

ResetIndexClass · 0.90
ToFrameClass · 0.90
RenameFrameClass · 0.90
SortValuesClass · 0.90
RearrangeByColumnClass · 0.90
SetIndexBlockwiseClass · 0.90
RenameSeriesClass · 0.90
IndexClass · 0.90
RepartitionClass · 0.90
is_index_likeFunction · 0.85
is_series_likeFunction · 0.85
setClass · 0.85

Tested by

no test coverage detected