From c045312e8f9f72e7abccb7109ffe6445cddf7f22 Mon Sep 17 00:00:00 2001 From: Nick Crews Date: Wed, 7 Feb 2024 11:50:49 -0900 Subject: [PATCH] chore: apply code review suggestions --- ibis/backends/tests/test_array.py | 28 ++++++++++++---------------- ibis/expr/types/arrays.py | 4 ++-- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/ibis/backends/tests/test_array.py b/ibis/backends/tests/test_array.py index 7f67fda8244b9..f67661e543960 100644 --- a/ibis/backends/tests/test_array.py +++ b/ibis/backends/tests/test_array.py @@ -449,11 +449,11 @@ def test_array_slice(backend, start, stop): ], ) @pytest.mark.parametrize( - "func,result_name", + "func", [ - (lambda x: x + 1, "ArrayMap(a, Add(x, 1))"), - (functools.partial(lambda x, y: x + y, y=1), "ArrayMap(a, Add(x, 1))"), - (ibis._ + 1, "ArrayMap(a, Add(_, 1))"), + lambda x: x + 1, + functools.partial(lambda x, y: x + y, y=1), + ibis._ + 1, ], ) @pytest.mark.broken( @@ -461,14 +461,12 @@ def test_array_slice(backend, start, stop): raises=AssertionError, reason="TODO(Kexiang): seems a bug", ) -def test_array_map(con, input, output, func, result_name): +def test_array_map(con, input, output, func): t = ibis.memtable(input, schema=ibis.schema(dict(a="!array"))) t = ibis.memtable(input, schema=ibis.schema(dict(a="!array"))) expected = pd.Series(output["a"]) - result = t.a.map(func) - assert result.get_name() == result_name - expr = t.select(a=result) + expr = t.select(a=t.a.map(func)) result = con.execute(expr.a) assert frozenset(map(tuple, result.values)) == frozenset( map(tuple, expected.values) @@ -517,20 +515,18 @@ def test_array_map(con, input, output, func, result_name): ], ) @pytest.mark.parametrize( - ("predicate,result_name"), + "predicate", [ - (lambda x: x > 1, "ArrayFilter(a, Greater(x, 1))"), - (functools.partial(lambda x, y: x > y, y=1), "ArrayFilter(a, Greater(x, 1))"), - (ibis._ > 1, "ArrayFilter(a, Greater(_, 1))"), + lambda x: x > 1, + functools.partial(lambda x, y: x > y, y=1), + ibis._ > 1, ], ) -def test_array_filter(con, input, output, predicate, result_name): +def test_array_filter(con, input, output, predicate): t = ibis.memtable(input, schema=ibis.schema(dict(a="!array"))) expected = pd.Series(output["a"]) - result = t.a.filter(predicate) - assert result.get_name() == result_name - expr = t.select(a=result) + expr = t.select(a=t.a.filter(predicate)) result = con.execute(expr.a) assert frozenset(map(tuple, result.values)) == frozenset( map(tuple, expected.values) diff --git a/ibis/expr/types/arrays.py b/ibis/expr/types/arrays.py index 8770dae66ef2d..54e0c739d802e 100644 --- a/ibis/expr/types/arrays.py +++ b/ibis/expr/types/arrays.py @@ -444,7 +444,7 @@ def map(self, func: Deferred | Callable[[ir.Value], ir.Value]) -> ir.ArrayValue: └────────────────────────┘ """ if isinstance(func, Deferred): - name = "_" + name = str(func) else: name = next(iter(inspect.signature(func).parameters.keys())) parameter = ops.Argument( @@ -544,7 +544,7 @@ def filter( └───────────────────────────────┘ """ if isinstance(predicate, Deferred): - name = "_" + name = str(predicate) else: name = next(iter(inspect.signature(predicate).parameters.keys())) parameter = ops.Argument(