Abstract shuffle class Parameters ---------- frame: Expr The DataFrame-like expression to shuffle. partitioning_index: str, list Column and/or index names to hash and partition by. npartitions: int Number of output partitions. ignore_index: bool
| 176 | |
| 177 | |
| 178 | class Shuffle(ShuffleBase): |
| 179 | """Abstract shuffle class |
| 180 | |
| 181 | Parameters |
| 182 | ---------- |
| 183 | frame: Expr |
| 184 | The DataFrame-like expression to shuffle. |
| 185 | partitioning_index: str, list |
| 186 | Column and/or index names to hash and partition by. |
| 187 | npartitions: int |
| 188 | Number of output partitions. |
| 189 | ignore_index: bool |
| 190 | Whether to ignore the index during this shuffle operation. |
| 191 | method: str or Callable |
| 192 | Label or callback function to convert a shuffle operation |
| 193 | to its necessary components. |
| 194 | options: dict |
| 195 | Algorithm-specific options. |
| 196 | index_shuffle : bool |
| 197 | Whether to perform the shuffle on the index. |
| 198 | """ |
| 199 | |
| 200 | def _lower(self): |
| 201 | # Use `method` to decide how to compose a |
| 202 | # shuffle operation from concrete expressions |
| 203 | |
| 204 | # Reduce partition count if necessary |
| 205 | frame = self.frame |
| 206 | npartitions_out = self.npartitions_out |
| 207 | method = self.method or get_default_shuffle_method() |
| 208 | |
| 209 | if npartitions_out < frame.npartitions and method != "p2p": |
| 210 | frame = Repartition(frame, new_partitions=npartitions_out) |
| 211 | |
| 212 | ops = [ |
| 213 | self.partitioning_index, |
| 214 | self.npartitions_out, |
| 215 | self.ignore_index, |
| 216 | self.options, |
| 217 | self.original_partitioning_index, |
| 218 | ] |
| 219 | if method == "p2p": |
| 220 | return P2PShuffle(frame, *ops) |
| 221 | elif method == "disk": |
| 222 | return DiskShuffle(frame, *ops) |
| 223 | elif method == "simple": |
| 224 | return SimpleShuffle(frame, *ops) |
| 225 | elif method == "tasks": |
| 226 | return TaskShuffle(frame, *ops) |
| 227 | else: |
| 228 | raise ValueError(f"{method} not supported") |
| 229 | |
| 230 | |
| 231 | def _is_numeric_cast_type(dtype): |