| 1426 | |
| 1427 | |
| 1428 | class RenameSeries(Elemwise): |
| 1429 | _parameters = ["frame", "index", "sorted_index"] |
| 1430 | _defaults = {"sorted_index": False} |
| 1431 | _filter_passthrough = True |
| 1432 | _preserves_partitioning_information = True |
| 1433 | |
| 1434 | @functools.cached_property |
| 1435 | def _meta(self): |
| 1436 | args = [ |
| 1437 | meta_nonempty(op._meta) if isinstance(op, Expr) else op for op in self._args |
| 1438 | ] |
| 1439 | return make_meta(self.operation(*args, **self._kwargs)) |
| 1440 | |
| 1441 | @staticmethod |
| 1442 | def operation(df, index, sorted_index): |
| 1443 | if is_series_like(df): |
| 1444 | return df.rename(index=index) |
| 1445 | return df.rename(name=index) |
| 1446 | |
| 1447 | def _divisions(self): |
| 1448 | index = self.operand("index") |
| 1449 | if is_scalar(index) and not isinstance(index, Callable): |
| 1450 | return self.frame.divisions |
| 1451 | elif self.sorted_index and self.frame.known_divisions: |
| 1452 | old = pd.Series(1, index=self.frame.divisions) |
| 1453 | new_divisions = old.rename(index).index |
| 1454 | if not new_divisions.is_monotonic_increasing: |
| 1455 | raise ValueError( |
| 1456 | "The renamer creates an Index with non-monotonic divisions. " |
| 1457 | "This is not allowed. Please set sorted_index=False." |
| 1458 | ) |
| 1459 | return tuple(new_divisions.tolist()) |
| 1460 | else: |
| 1461 | return (None,) * (self.frame.npartitions + 1) |
| 1462 | |
| 1463 | |
| 1464 | class Fillna(Elemwise): |