From 9e9ef6eb8e5d4f30bedbff5260a55c453d1a5ca2 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Sat, 26 Aug 2023 22:09:33 +0200 Subject: [PATCH] Fix tests again --- py-polars/tests/test_udfs.py | 12 ++++++------ .../unit/operations/test_inefficient_apply.py | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/py-polars/tests/test_udfs.py b/py-polars/tests/test_udfs.py index f661edaf7f23..956edaecd1f6 100644 --- a/py-polars/tests/test_udfs.py +++ b/py-polars/tests/test_udfs.py @@ -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 @@ -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}"));' ) @@ -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") @@ -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"));' ) @@ -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")' diff --git a/py-polars/tests/unit/operations/test_inefficient_apply.py b/py-polars/tests/unit/operations/test_inefficient_apply.py index 718aac6e522a..be5440b1c854 100644 --- a/py-polars/tests/unit/operations/test_inefficient_apply.py +++ b/py-polars/tests/unit/operations/test_inefficient_apply.py @@ -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") @@ -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 @@ -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 @@ -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 @@ -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" @@ -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