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

Function determine_column_projection

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

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