Column Assignment
| 1955 | |
| 1956 | |
| 1957 | class Assign(Elemwise): |
| 1958 | """Column Assignment""" |
| 1959 | |
| 1960 | _parameters = ["frame"] |
| 1961 | operation = staticmethod(assign) |
| 1962 | |
| 1963 | @functools.cached_property |
| 1964 | def unique_partition_mapping_columns_from_shuffle(self): |
| 1965 | keys = set(self.keys) |
| 1966 | return { |
| 1967 | col |
| 1968 | for col in self.frame.unique_partition_mapping_columns_from_shuffle |
| 1969 | if not isinstance(col, tuple) |
| 1970 | and col not in keys |
| 1971 | or not set(col).intersection(keys) |
| 1972 | } |
| 1973 | |
| 1974 | @functools.cached_property |
| 1975 | def keys(self): |
| 1976 | return self.operands[1::2] |
| 1977 | |
| 1978 | @functools.cached_property |
| 1979 | def vals(self): |
| 1980 | return self.operands[2::2] |
| 1981 | |
| 1982 | @functools.cached_property |
| 1983 | def _meta(self): |
| 1984 | args = [op._meta if isinstance(op, Expr) else op for op in self._args] |
| 1985 | return make_meta(self.operation(*args, **self._kwargs)) |
| 1986 | |
| 1987 | def _tree_repr_argument_construction(self, i, op, header): |
| 1988 | if i == 0: |
| 1989 | return super()._tree_repr_argument_construction(i, op, header) |
| 1990 | if i % 2 == 1: |
| 1991 | sep = "" if i == 1 else "," |
| 1992 | header += f"{sep} {repr(op)[1:-1]}=" |
| 1993 | else: |
| 1994 | header += f"{repr(op)}" |
| 1995 | return header |
| 1996 | |
| 1997 | def _node_label_args(self): |
| 1998 | return self.operands |
| 1999 | |
| 2000 | def _remove_common_columns(self, other): |
| 2001 | if set(self.keys) & set(other.keys): |
| 2002 | keys = set(self.keys) |
| 2003 | operands = [[k, v] for k, v in zip(other.keys, other.vals) if k not in keys] |
| 2004 | return [other.frame] + list(flatten(operands)) + self.operands[1:] |
| 2005 | else: |
| 2006 | return other.operands + self.operands[1:] |
| 2007 | |
| 2008 | def _simplify_down(self): |
| 2009 | if isinstance(self.frame, Assign): |
| 2010 | if self._check_for_previously_created_column(self.frame): |
| 2011 | # don't squash if we are using a column that was previously created |
| 2012 | return |
| 2013 | return Assign(*self._remove_common_columns(self.frame)) |
| 2014 | elif isinstance(self.frame, Projection) and isinstance( |