Skip to content

Commit

Permalink
Fix tests again
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Aug 26, 2023
1 parent d413185 commit 9e9ef6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions py-polars/tests/test_udfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def test_bytecode_parser_expression(col: str, func: str, expected: str) -> None:
# won't be skipped.
return

bytecode_parser = udfs.BytecodeParser(eval(func), apply_target="expr")
bytecode_parser = udfs.BytecodeParser(eval(func), map_target="expr")
result = bytecode_parser.to_expression(col)
assert result == expected

Expand Down Expand Up @@ -197,7 +197,7 @@ def test_bytecode_parser_expression_in_ipython(
"import numpy as np; "
"import json; "
f"MY_DICT = {MY_DICT};"
f'bytecode_parser = udfs.BytecodeParser({func}, apply_target="expr");'
f'bytecode_parser = udfs.BytecodeParser({func}, map_target="expr");'
f'print(bytecode_parser.to_expression("{col}"));'
)

Expand All @@ -220,7 +220,7 @@ def test_bytecode_parser_expression_noop(func: str) -> None:
# won't be skipped.
return

parser = udfs.BytecodeParser(eval(func), apply_target="expr")
parser = udfs.BytecodeParser(eval(func), map_target="expr")
assert not parser.can_attempt_rewrite() or not parser.to_expression("x")


Expand All @@ -242,7 +242,7 @@ def test_bytecode_parser_expression_noop_in_ipython(func: str) -> None:
script = (
"import udfs; "
f"MY_DICT = {MY_DICT};"
f'parser = udfs.BytecodeParser({func}, apply_target="expr");'
f'parser = udfs.BytecodeParser({func}, map_target="expr");'
f'print(not parser.can_attempt_rewrite() or not parser.to_expression("x"));'
)

Expand All @@ -259,13 +259,13 @@ def test_local_imports() -> None:
import datetime as dt # noqa: F811
import json

bytecode_parser = udfs.BytecodeParser(lambda x: json.loads(x), apply_target="expr")
bytecode_parser = udfs.BytecodeParser(lambda x: json.loads(x), map_target="expr")
result = bytecode_parser.to_expression("x")
expected = 'pl.col("x").str.json_extract()'
assert result == expected

bytecode_parser = udfs.BytecodeParser(
lambda x: dt.datetime.strptime(x, "%Y-%m-%d"), apply_target="expr"
lambda x: dt.datetime.strptime(x, "%Y-%m-%d"), map_target="expr"
)
result = bytecode_parser.to_expression("x")
expected = 'pl.col("x").str.to_datetime(format="%Y-%m-%d")'
Expand Down
18 changes: 9 additions & 9 deletions py-polars/tests/unit/operations/test_inefficient_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
)
def test_parse_invalid_function(func: str) -> None:
# functions we don't (yet?) offer suggestions for
parser = BytecodeParser(eval(func), apply_target="expr")
parser = BytecodeParser(eval(func), map_target="expr")
assert not parser.can_attempt_rewrite() or not parser.to_expression("x")


Expand All @@ -47,7 +47,7 @@ def test_parse_apply_functions(col: str, func: str, expr_repr: str) -> None:
PolarsInefficientMapWarning,
match=r"(?s)Expr\.map_elements.*In this case, you can replace",
):
parser = BytecodeParser(eval(func), apply_target="expr")
parser = BytecodeParser(eval(func), map_target="expr")
suggested_expression = parser.to_expression(col)
assert suggested_expression == expr_repr

Expand Down Expand Up @@ -78,7 +78,7 @@ def test_parse_apply_raw_functions() -> None:
func = getattr(numpy, func_name)

# note: we can't parse/rewrite raw numpy functions...
parser = BytecodeParser(func, apply_target="expr")
parser = BytecodeParser(func, map_target="expr")
assert not parser.can_attempt_rewrite()

# ...but we ARE still able to warn
Expand Down Expand Up @@ -127,13 +127,13 @@ class Test:
def x10(self, x: pl.Expr) -> pl.Expr:
return x * 10

parser = BytecodeParser(Test().x10, apply_target="expr")
parser = BytecodeParser(Test().x10, map_target="expr")
suggested_expression = parser.to_expression(col="colx")
assert suggested_expression == 'pl.col("colx") * 10'

# note: all constants - should not create a warning/suggestion
suggested_expression = BytecodeParser(
lambda x: MY_CONSTANT + 42, apply_target="expr"
lambda x: MY_CONSTANT + 42, map_target="expr"
).to_expression(col="colx")
assert suggested_expression is None

Expand All @@ -152,9 +152,9 @@ def x10(self, x: pl.Expr) -> pl.Expr:
# used in the user warning will fall back (in priority order) through
# various aliases until it finds one that is available.
s, srs, series = -1, 0, 1
expr1 = BytecodeParser(lambda x: x + s, apply_target="series")
expr2 = BytecodeParser(lambda x: srs + x + s, apply_target="series")
expr3 = BytecodeParser(lambda x: srs + x + s - x + series, apply_target="series")
expr1 = BytecodeParser(lambda x: x + s, map_target="series")
expr2 = BytecodeParser(lambda x: srs + x + s, map_target="series")
expr3 = BytecodeParser(lambda x: srs + x + s - x + series, map_target="series")

assert expr1.to_expression(col="srs") == "srs + s"
assert expr2.to_expression(col="srs") == "(srs + series) + s"
Expand Down Expand Up @@ -185,7 +185,7 @@ def test_parse_apply_series(
):
s = pl.Series("srs", data)

parser = BytecodeParser(func, apply_target="series")
parser = BytecodeParser(func, map_target="series")
suggested_expression = parser.to_expression(s.name)
assert suggested_expression == expr_repr

Expand Down

0 comments on commit 9e9ef6e

Please sign in to comment.