Skip to content

Commit 44f4883

Browse files
committed
Fix for arange
1 parent 1d60dcd commit 44f4883

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/blosc2/ndarray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5847,7 +5847,7 @@ def ramp_arange(start, step):
58475847
)
58485848
dtype = _check_dtype(dtype)
58495849

5850-
if is_inside_new_expr() or NUM < 0:
5850+
if is_inside_new_expr() or NUM == 0:
58515851
# We already have the dtype and shape, so return immediately
58525852
return blosc2.zeros(shape, dtype=dtype, **kwargs)
58535853

tests/ndarray/test_ndarray.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,25 @@ def test_arange(sss, shape, dtype, chunks, blocks, c_order):
207207
pass
208208

209209

210+
@pytest.mark.parametrize(
211+
("start", "stop", "step"),
212+
[
213+
(10, 2, 1), # stop < start, positive step
214+
(2, 10, -1), # start < stop, negative step
215+
(5, 5, 1), # start == stop
216+
(0, 0, 1), # both zero
217+
],
218+
)
219+
def test_arange_empty(start, stop, step):
220+
"""blosc2.arange() should return an empty array when the range is empty, like numpy."""
221+
a = blosc2.arange(start, stop, step)
222+
b = np.arange(start, stop, step)
223+
assert a.shape == b.shape
224+
assert a.shape == (0,)
225+
assert isinstance(a, blosc2.NDArray)
226+
np.testing.assert_array_equal(a[:], b)
227+
228+
210229
@pytest.mark.parametrize(
211230
("ss", "shape", "dtype", "chunks", "blocks"),
212231
[

0 commit comments

Comments
 (0)