MCPcopy Create free account
hub / github.com/dask/dask / determine_column_projection

Function determine_column_projection

dask/dataframe/dask_expr/_expr.py:3897–3934  ·  view source on GitHub ↗
(
    expr: Expr,
    parent: Expr,
    dependents: dict[str, Collection[weakref.ref[BaseExpr]]],
    additional_columns: list | None = None,
)

Source from the content-addressed store, hash-verified

3895
3896
3897def determine_column_projection(
3898 expr: Expr,
3899 parent: Expr,
3900 dependents: dict[str, Collection[weakref.ref[BaseExpr]]],
3901 additional_columns: list | None = None,
3902) -> object:
3903 if isinstance(parent, Index):
3904 column_union = []
3905 else:
3906 column_union = parent.columns.copy()
3907 parents: list[Expr]
3908 parents = [inst for x in dependents[expr._name] if isinstance((inst := x()), Expr)]
3909
3910 seen = set()
3911 for p in parents:
3912 if p._name in seen:
3913 continue
3914 seen.add(p._name)
3915 column_union.extend(p._projection_columns)
3916
3917 if additional_columns is not None:
3918 column_union.extend(flatten(additional_columns, container=list))
3919
3920 # We can end up with MultiIndex columns from groupby ops, needs to be
3921 # accounted for in the sort
3922 flattened_columns = set(column_union)
3923 try:
3924 column_union = sorted(flattened_columns)
3925 except TypeError:
3926 # mixed type columns
3927 column_union = _sort_mixed(pd.Index(list(flattened_columns))).tolist()
3928 if (
3929 len(column_union) == 1
3930 and parent.ndim == 1
3931 and all(p.ndim == 1 for p in parents)
3932 ):
3933 return column_union[0]
3934 return column_union
3935
3936
3937def _sort_mixed(values):

Callers 15

groupby_projectionFunction · 0.90
_simplify_upMethod · 0.90
_simplify_upMethod · 0.90
_simplify_upMethod · 0.90
_simplify_upMethod · 0.90
_simplify_upMethod · 0.90
_simplify_upMethod · 0.90
_simplify_upMethod · 0.90
_simplify_upMethod · 0.90
_simplify_upMethod · 0.90
_simplify_upMethod · 0.90
_simplify_upMethod · 0.85

Calls 6

flattenFunction · 0.90
setClass · 0.85
_sort_mixedFunction · 0.85
allFunction · 0.85
copyMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected