| 1284 | |
| 1285 | |
| 1286 | class SetIndexBlockwise(Blockwise): |
| 1287 | _parameters = ["frame", "other", "drop", "new_divisions", "append"] |
| 1288 | _defaults = {"append": False, "new_divisions": None, "drop": True} |
| 1289 | _keyword_only = ["drop", "new_divisions", "append"] |
| 1290 | _is_length_preserving = True |
| 1291 | _preserves_partitioning_information = True |
| 1292 | |
| 1293 | @staticmethod |
| 1294 | def operation(df, *args, new_divisions, **kwargs): |
| 1295 | return df.set_index(*args, **kwargs) |
| 1296 | |
| 1297 | def _divisions(self): |
| 1298 | if self.new_divisions is None: |
| 1299 | return (None,) * (self.frame.npartitions + 1) |
| 1300 | return tuple(self.new_divisions) |
| 1301 | |
| 1302 | def _simplify_up(self, parent, dependents): |
| 1303 | if isinstance(parent, Projection): |
| 1304 | columns = determine_column_projection( |
| 1305 | self, |
| 1306 | parent, |
| 1307 | dependents, |
| 1308 | additional_columns=_convert_to_list(self.other), |
| 1309 | ) |
| 1310 | if self.frame.columns == columns: |
| 1311 | return |
| 1312 | columns = [col for col in self.frame.columns if col in columns] |
| 1313 | return type(parent)( |
| 1314 | type(self)(self.frame[columns], *self.operands[1:]), |
| 1315 | parent.operand("columns"), |
| 1316 | ) |
| 1317 | |
| 1318 | |
| 1319 | divisions_lru = LRU(10) # type: ignore |