Skip to content

Commit

Permalink
Remove deprecated ExtContext node (#16001)
Browse files Browse the repository at this point in the history
Polars deprecated with_context in the alpha for version 1, and will remove it for version 1. So let's not bother implementing it. Also add some no-cover pragmas to unreachable code in the translation DSL layer.

Authors:
  - Lawrence Mitchell (https://github.com/wence-)

Approvers:
  - Thomas Li (https://github.com/lithomas1)

URL: #16001
  • Loading branch information
wence- authored Jun 18, 2024
1 parent 0bdf934 commit dcc153b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 61 deletions.
31 changes: 7 additions & 24 deletions python/cudf_polars/cudf_polars/dsl/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import itertools
import types
from functools import cache
from typing import TYPE_CHECKING, Any, Callable, ClassVar, NoReturn
from typing import TYPE_CHECKING, Any, Callable, ClassVar

import pyarrow as pa
from typing_extensions import assert_never
Expand Down Expand Up @@ -56,7 +56,6 @@
"MapFunction",
"Union",
"HConcat",
"ExtContext",
]


Expand Down Expand Up @@ -153,7 +152,9 @@ def evaluate(self, *, cache: MutableMapping[int, DataFrame]) -> DataFrame:
since the translation phase should pick up things that we
cannot handle.
"""
raise NotImplementedError
raise NotImplementedError(
f"Evaluation of plan {type(self).__name__}"
) # pragma: no cover


@dataclasses.dataclass(slots=True)
Expand Down Expand Up @@ -346,7 +347,9 @@ class Reduce(IR):
expr: list[expr.NamedExpr]
"""List of expressions to evaluate to form the new dataframe."""

def evaluate(self, *, cache: MutableMapping[int, DataFrame]) -> DataFrame:
def evaluate(
self, *, cache: MutableMapping[int, DataFrame]
) -> DataFrame: # pragma: no cover; polars doesn't emit this node yet
"""Evaluate and return a dataframe."""
df = self.df.evaluate(cache=cache)
columns = broadcast(*(e.evaluate(df) for e in self.expr))
Expand Down Expand Up @@ -938,23 +941,3 @@ def evaluate(self, *, cache: MutableMapping[int, DataFrame]) -> DataFrame:
return DataFrame(
list(itertools.chain.from_iterable(df.columns for df in dfs)),
)


@dataclasses.dataclass(slots=True)
class ExtContext(IR):
"""
Concatenate dataframes horizontally.
Prefer HConcat, since this is going to be deprecated on the polars side.
"""

df: IR
"""Input."""
extra: list[IR]
"""List of extra inputs."""

def __post_init__(self) -> NoReturn:
"""Validate preconditions."""
raise NotImplementedError(
"ExtContext will be deprecated, use horizontal concat instead."
)
21 changes: 7 additions & 14 deletions python/cudf_polars/cudf_polars/dsl/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def __exit__(self, *args: Any) -> None:
def _translate_ir(
node: Any, visitor: NodeTraverser, schema: dict[str, plc.DataType]
) -> ir.IR:
raise NotImplementedError(f"Translation for {type(node).__name__}")
raise NotImplementedError(
f"Translation for {type(node).__name__}"
) # pragma: no cover


@_translate_ir.register
Expand Down Expand Up @@ -172,7 +174,7 @@ def _(
@_translate_ir.register
def _(
node: pl_ir.Reduce, visitor: NodeTraverser, schema: dict[str, plc.DataType]
) -> ir.IR:
) -> ir.IR: # pragma: no cover; polars doesn't emit this node yet
with set_node(visitor, node.input):
inp = translate_ir(visitor, n=None)
exprs = [translate_named_expr(visitor, n=e) for e in node.expr]
Expand Down Expand Up @@ -256,17 +258,6 @@ def _(
return ir.HConcat(schema, [translate_ir(visitor, n=n) for n in node.inputs])


@_translate_ir.register
def _(
node: pl_ir.ExtContext, visitor: NodeTraverser, schema: dict[str, plc.DataType]
) -> ir.IR:
return ir.ExtContext(
schema,
translate_ir(visitor, n=node.input),
[translate_ir(visitor, n=n) for n in node.contexts],
)


def translate_ir(visitor: NodeTraverser, *, n: int | None = None) -> ir.IR:
"""
Translate a polars-internal IR node to our representation.
Expand Down Expand Up @@ -333,7 +324,9 @@ def translate_named_expr(
def _translate_expr(
node: Any, visitor: NodeTraverser, dtype: plc.DataType
) -> expr.Expr:
raise NotImplementedError(f"Translation for {type(node).__name__}")
raise NotImplementedError(
f"Translation for {type(node).__name__}"
) # pragma: no cover


@_translate_expr.register
Expand Down
23 changes: 0 additions & 23 deletions python/cudf_polars/tests/test_extcontext.py

This file was deleted.

0 comments on commit dcc153b

Please sign in to comment.