Skip to content

Commit 13f9e6f

Browse files
apronchenkovcopybara-github
authored andcommitted
Fix lazy inputs support in as_qvalue_or_expr_with_list_to_slice_support
PiperOrigin-RevId: 863576628 Change-Id: Icc7b895de06d7d53f9a56da3c3a1417307cb2e86
1 parent b249d4a commit 13f9e6f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

py/koladata/types/py_boxing.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,17 @@ def _wrap(x: Any) -> arolla.Expr | arolla.QValue:
167167
return data_item.DataItem.from_vals(arg)
168168

169169

170+
_make_slice_op = arolla.abc.unsafe_make_registered_operator('kd.slices.slice')
171+
172+
170173
def as_qvalue_or_expr_with_list_to_slice_support(
171174
arg: Any,
172175
) -> arolla.Expr | arolla.QValue:
173-
if isinstance(arg, list):
174-
return data_slice.DataSlice.from_vals(arg)
175-
return as_qvalue_or_expr(arg)
176+
"""Converts Python values into QValues or Exprs, supporting list to slice."""
177+
if not isinstance(arg, list):
178+
return as_qvalue_or_expr(arg)
179+
result, _ = arolla.abc.aux_bind_arguments(_make_slice_op, arg)
180+
return result
176181

177182

178183
def as_qvalue_or_expr_with_py_function_to_py_object_support(

py/koladata/types/py_boxing_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def test_register_py_function_boxing_fn(self):
126126
(arolla.L.x, arolla.L.x),
127127
((1, 2), arolla.tuple(ds(1), ds(2))),
128128
([1, 2], ds([1, 2])),
129+
([[1]], ds([[1]])),
129130
)
130131
def test_as_qvalue_or_expr_with_list_to_slice_support(
131132
self, value, expected_res
@@ -135,6 +136,18 @@ def test_as_qvalue_or_expr_with_list_to_slice_support(
135136
expected_res,
136137
)
137138

139+
def test_as_qvalue_or_expr_with_list_to_slice_exprs(self):
140+
testing.assert_equal(
141+
arolla.eval(
142+
py_boxing.as_qvalue_or_expr_with_list_to_slice_support(
143+
[[1], [arolla.L.x], [arolla.L.y]]
144+
),
145+
x=ds(2),
146+
y=ds(3),
147+
),
148+
ds([[1], [2], [3]]),
149+
)
150+
138151
def test_as_qvalue_or_expr_with_py_function_to_py_object_support(self):
139152
fn = lambda x: x
140153
self.assertIsInstance(

0 commit comments

Comments
 (0)