diff --git a/arkouda/numpy/pdarraycreation.py b/arkouda/numpy/pdarraycreation.py index 5dba8ac4f9d..7016a543447 100644 --- a/arkouda/numpy/pdarraycreation.py +++ b/arkouda/numpy/pdarraycreation.py @@ -1426,6 +1426,17 @@ def linspace( start_ = start stop_ = stop + # Handle the special cases of num + + if num == 0: + return array([], dtype=float64) + + if num == 1: + if isinstance(start_, pdarray): + return start_.reshape((1,) + start_.shape) + else: + return array([start_], dtype=float64) + if isinstance(start_, pdarray): start_ = start_.astype(float64) elif isinstance(start_, int): diff --git a/tests/numpy/pdarray_creation_test.py b/tests/numpy/pdarray_creation_test.py index a39c9ae4477..6578a2ccd12 100644 --- a/tests/numpy/pdarray_creation_test.py +++ b/tests/numpy/pdarray_creation_test.py @@ -816,6 +816,14 @@ def test_full_like_multi_dim(self, size, dtype): assert (full_like_arr == 1).all() assert full_like_arr.size == ran_arr.size + def test_linspace_special_cases(self): + pda = ak.linspace(0, 1, 0, endpoint=True) + nda = np.linspace(0, 1, 0, endpoint=True) + assert_almost_equivalent(pda, nda) + pda = ak.linspace(0, 1, 1, endpoint=True) + nda = np.linspace(0, 1, 1, endpoint=True) + assert_almost_equivalent(pda, nda) + @pytest.mark.parametrize("size", pytest.prob_size) def test_linspace_1D(self, size): pda = ak.linspace(0, 100, size)