Column Assignment
| 1975 | |
| 1976 | |
| 1977 | class Assign(Elemwise): |
| 1978 | """Column Assignment""" |
| 1979 | |
| 1980 | _parameters = ["frame"] |
| 1981 | operation = staticmethod(assign) |
| 1982 | |
| 1983 | @functools.cached_property |
| 1984 | def unique_partition_mapping_columns_from_shuffle(self): |
| 1985 | keys = set(self.keys) |
| 1986 | return { |
| 1987 | col |
| 1988 | for col in self.frame.unique_partition_mapping_columns_from_shuffle |
| 1989 | if not isinstance(col, tuple) |
| 1990 | and col not in keys |
| 1991 | or not set(col).intersection(keys) |
| 1992 | } |
| 1993 | |
| 1994 | @functools.cached_property |
| 1995 | def keys(self): |
| 1996 | return self.operands[1::2] |
| 1997 | |
| 1998 | @functools.cached_property |
| 1999 | def vals(self): |
| 2000 | return self.operands[2::2] |
| 2001 | |
| 2002 | @functools.cached_property |
| 2003 | def _meta(self): |
| 2004 | args = [op._meta if isinstance(op, Expr) else op for op in self._args] |
| 2005 | return make_meta(self.operation(*args, **self._kwargs)) |
| 2006 | |
| 2007 | def _tree_repr_argument_construction(self, i, op, header): |
| 2008 | if i == 0: |
| 2009 | return super()._tree_repr_argument_construction(i, op, header) |
| 2010 | if i % 2 == 1: |
| 2011 | sep = "" if i == 1 else "," |
| 2012 | header += f"{sep} {repr(op)[1:-1]}=" |
| 2013 | else: |
| 2014 | header += f"{op!r}" |
| 2015 | return header |
| 2016 | |
| 2017 | def _node_label_args(self): |
| 2018 | return self.operands |
| 2019 | |
| 2020 | def _remove_common_columns(self, other): |
| 2021 | if set(self.keys) & set(other.keys): |
| 2022 | keys = set(self.keys) |
| 2023 | operands = [[k, v] for k, v in zip(other.keys, other.vals) if k not in keys] |
| 2024 | return [other.frame] + list(flatten(operands)) + self.operands[1:] |
| 2025 | else: |
| 2026 | return other.operands + self.operands[1:] |
| 2027 | |
| 2028 | def _simplify_down(self): |
| 2029 | if isinstance(self.frame, Assign): |
| 2030 | if self._check_for_previously_created_column(self.frame): |
| 2031 | # don't squash if we are using a column that was previously created |
| 2032 | return |
| 2033 | return Assign(*self._remove_common_columns(self.frame)) |
| 2034 | elif isinstance(self.frame, Projection) and isinstance( |