MCPcopy
hub / github.com/dask/dask / Projection

Class Projection

dask/dataframe/dask_expr/_expr.py:2173–2245  ·  view source on GitHub ↗

Column Selection

Source from the content-addressed store, hash-verified

2171
2172
2173class Projection(Elemwise):
2174 """Column Selection"""
2175
2176 _parameters = ["frame", "columns"]
2177 operation = operator.getitem
2178
2179 @functools.cached_property
2180 def unique_partition_mapping_columns_from_shuffle(self):
2181 col_op = self.operand("columns")
2182 columns = set(col_op) if isinstance(col_op, list) else {col_op}
2183 return {
2184 c
2185 for c in self.frame.unique_partition_mapping_columns_from_shuffle
2186 if c in columns or isinstance(c, tuple) and set(c).issubset(columns)
2187 }
2188
2189 @property
2190 def columns(self):
2191 cols = self.operand("columns")
2192 if isinstance(cols, list):
2193 return cols
2194 elif isinstance(cols, pd.Index):
2195 return list(cols)
2196 else:
2197 return [cols]
2198
2199 @functools.cached_property
2200 def _meta(self):
2201 if is_dataframe_like(self.frame._meta):
2202 return super()._meta
2203 # if we are not a DataFrame and have a scalar, we reduce to a scalar
2204 if not isinstance(self.operand("columns"), (list, slice)) and not hasattr(
2205 self.operand("columns"), "dtype"
2206 ):
2207 return meta_nonempty(self.frame._meta).iloc[0]
2208 # Avoid column selection for Series/Index
2209 return self.frame._meta
2210
2211 def _node_label_args(self):
2212 return [self.frame, self.operand("columns")]
2213
2214 def __str__(self):
2215 base = str(self.frame)
2216 if " " in base:
2217 base = f"({base})"
2218 return f"{base}[{self.operand('columns')!r}]"
2219
2220 def _divisions(self):
2221 if self.ndim == 0:
2222 return (None, None)
2223 return super()._divisions()
2224
2225 def _simplify_down(self):
2226 if (
2227 str(self.frame.columns) == str(self.columns)
2228 and self._meta.ndim == self.frame._meta.ndim
2229 ):
2230 # TODO: we should get more precise around Expr.columns types

Callers 12

_lowerMethod · 0.90
__getitem__Method · 0.90
_locMethod · 0.90
_loc_seriesMethod · 0.90
_lowerMethod · 0.90
_lowerMethod · 0.90
_simplify_downMethod · 0.90
__getitem__Method · 0.85
_simplify_upMethod · 0.85
_simplify_downMethod · 0.85
_simplify_downMethod · 0.85
_simplify_upMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…