File tree 2 files changed +27
-1
lines changed
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -1488,3 +1488,29 @@ def execute_array_index(op, **kw):
1488
1488
arg = translate (op .arg , ** kw )
1489
1489
index = translate (op .index , ** kw )
1490
1490
return arg .list .get (index )
1491
+
1492
+
1493
+ @translate .register (ops .ArraySlice )
1494
+ def visit_ArraySlice (op , ** kw ):
1495
+ arg = translate (op .arg , ** kw )
1496
+ arg_length = arg .list .len ()
1497
+
1498
+ start = translate (op .start , ** kw ) if op .start is not None else 0
1499
+ stop = translate (op .stop , ** kw ) if op .stop is not None else arg_length
1500
+
1501
+ def normalize_index (index , length ):
1502
+ index = pl .when (index < 0 ).then (length + index ).otherwise (index )
1503
+ return (
1504
+ pl .when (index < 0 )
1505
+ .then (0 )
1506
+ .when (index > length )
1507
+ .then (length )
1508
+ .otherwise (index )
1509
+ )
1510
+
1511
+ start = normalize_index (start , arg_length )
1512
+ stop = normalize_index (stop , arg_length )
1513
+
1514
+ slice_len = pl .when (stop > start ).then (stop - start ).otherwise (0 )
1515
+
1516
+ return arg .list .slice (start , slice_len )
Original file line number Diff line number Diff line change @@ -406,7 +406,7 @@ def test_unnest_default_name(backend):
406
406
),
407
407
],
408
408
)
409
- @pytest .mark .notimpl (["datafusion" , "polars" ], raises = com .OperationNotDefinedError )
409
+ @pytest .mark .notimpl (["datafusion" ], raises = com .OperationNotDefinedError )
410
410
def test_array_slice (backend , start , stop ):
411
411
array_types = backend .array_types
412
412
expr = array_types .select (sliced = array_types .y [start :stop ])
You can’t perform that action at this time.
0 commit comments