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

Function determine_column_projection

dask/dataframe/dask_expr/_expr.py:3853–3890  ·  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

3851
3852
3853def determine_column_projection(
3854 expr: Expr,
3855 parent: Expr,
3856 dependents: dict[str, Collection[weakref.ref[BaseExpr]]],
3857 additional_columns: list | None = None,
3858) -> object:
3859 if isinstance(parent, Index):
3860 column_union = []
3861 else:
3862 column_union = parent.columns.copy()
3863 parents: list[Expr]
3864 parents = [inst for x in dependents[expr._name] if isinstance((inst := x()), Expr)]
3865
3866 seen = set()
3867 for p in parents:
3868 if p._name in seen:
3869 continue
3870 seen.add(p._name)
3871 column_union.extend(p._projection_columns)
3872
3873 if additional_columns is not None:
3874 column_union.extend(flatten(additional_columns, container=list))
3875
3876 # We can end up with MultiIndex columns from groupby ops, needs to be
3877 # accounted for in the sort
3878 flattened_columns = set(column_union)
3879 try:
3880 column_union = sorted(flattened_columns)
3881 except TypeError:
3882 # mixed type columns
3883 column_union = _sort_mixed(pd.Index(list(flattened_columns))).tolist()
3884 if (
3885 len(column_union) == 1
3886 and parent.ndim == 1
3887 and all(p.ndim == 1 for p in parents)
3888 ):
3889 return column_union[0]
3890 return column_union
3891
3892
3893def _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