Skip to content

Commit 322cff9

Browse files
committed
progress
1 parent 02d40a1 commit 322cff9

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/_arraykit.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3354,7 +3354,19 @@ slice_to_ascending_slice(PyObject *Py_UNUSED(m), PyObject *args) {
33543354
&start,
33553355
&stop,
33563356
step);
3357-
Py_RETURN_NONE;
3357+
3358+
PyObject* asc_start = PyLong_FromSsize_t(stop + 1);
3359+
PyObject* asc_stop = PyLong_FromSsize_t(start + 1);
3360+
PyObject* asc_step = PyLong_FromSsize_t(-step);
3361+
3362+
// might be NULL, let return
3363+
PyObject* asc = PySlice_New(asc_start, asc_stop, asc_step);
3364+
3365+
Py_DECREF(asc_start);
3366+
Py_DECREF(asc_stop);
3367+
Py_DECREF(asc_step);
3368+
3369+
return asc;
33583370
}
33593371

33603372
//------------------------------------------------------------------------------

test/test_util.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,12 +705,14 @@ def test_first_true_2d_h(self) -> None:
705705

706706
#---------------------------------------------------------------------------
707707
def test_slice_to_ascending_slice_a(self) -> None:
708-
self.assertEqual(slice_to_ascending_slice(slice(5, 2, -1), 6),
709-
None,
708+
self.assertEqual(slice_to_ascending_slice(
709+
slice(5, 2, -1), 6),
710+
slice(3, 6, 1),
710711
)
711712

712713
def test_slice_to_ascending_slice_b(self) -> None:
713-
self.assertEqual(slice_to_ascending_slice(slice(2, 5, 1), 6),
714+
self.assertEqual(slice_to_ascending_slice(
715+
slice(2, 5, 1), 6),
714716
slice(2, 5, 1),
715717
)
716718

0 commit comments

Comments
 (0)