Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(python): Add private LazyFrame method for setting sink optimizations #10988

Merged
merged 4 commits into from
Sep 8, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 50 additions & 45 deletions py-polars/polars/lazyframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1886,22 +1886,15 @@ def sink_parquet(
>>> lf.sink_parquet("out.parquet") # doctest: +SKIP

"""
if no_optimization:
predicate_pushdown = False
projection_pushdown = False
slice_pushdown = False

lf = self._ldf.optimization_toggle(
type_coercion,
predicate_pushdown,
projection_pushdown,
simplify_expression,
slice_pushdown,
comm_subplan_elim=False,
comm_subexpr_elim=False,
streaming=True,
eager=False,
lf = self._set_sink_optimizations(
type_coercion=type_coercion,
predicate_pushdown=predicate_pushdown,
projection_pushdown=projection_pushdown,
simplify_expression=simplify_expression,
no_optimization=no_optimization,
slice_pushdown=slice_pushdown,
)

return lf.sink_parquet(
path=path,
compression=compression,
Expand Down Expand Up @@ -1963,22 +1956,15 @@ def sink_ipc(
>>> lf.sink_ipc("out.arrow") # doctest: +SKIP

"""
if no_optimization:
predicate_pushdown = False
projection_pushdown = False
slice_pushdown = False

lf = self._ldf.optimization_toggle(
type_coercion,
predicate_pushdown,
projection_pushdown,
simplify_expression,
slice_pushdown,
comm_subplan_elim=False,
comm_subexpr_elim=False,
streaming=True,
eager=False,
lf = self._set_sink_optimizations(
type_coercion=type_coercion,
predicate_pushdown=predicate_pushdown,
projection_pushdown=projection_pushdown,
simplify_expression=simplify_expression,
no_optimization=no_optimization,
slice_pushdown=slice_pushdown,
)

return lf.sink_ipc(
path=path,
compression=compression,
Expand Down Expand Up @@ -2092,21 +2078,13 @@ def sink_csv(
if not null_value:
null_value = None

if no_optimization:
predicate_pushdown = False
projection_pushdown = False
slice_pushdown = False

lf = self._ldf.optimization_toggle(
type_coercion,
predicate_pushdown,
projection_pushdown,
simplify_expression,
slice_pushdown,
comm_subplan_elim=False,
comm_subexpr_elim=False,
streaming=True,
eager=False,
lf = self._set_sink_optimizations(
type_coercion=type_coercion,
predicate_pushdown=predicate_pushdown,
projection_pushdown=projection_pushdown,
simplify_expression=simplify_expression,
no_optimization=no_optimization,
slice_pushdown=slice_pushdown,
)

return lf.sink_csv(
Expand All @@ -2125,6 +2103,33 @@ def sink_csv(
maintain_order=maintain_order,
)

def _set_sink_optimizations(
self,
*,
type_coercion: bool = True,
predicate_pushdown: bool = True,
projection_pushdown: bool = True,
simplify_expression: bool = True,
no_optimization: bool = False,
slice_pushdown: bool = True,
) -> PyLazyFrame:
if no_optimization:
predicate_pushdown = False
projection_pushdown = False
slice_pushdown = False

return self._ldf.optimization_toggle(
type_coercion,
predicate_pushdown,
projection_pushdown,
simplify_expression,
slice_pushdown,
comm_subplan_elim=False,
comm_subexpr_elim=False,
streaming=True,
eager=False,
)

@deprecate_renamed_parameter(
"common_subplan_elimination", "comm_subplan_elim", version="0.18.9"
)
Expand Down