summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarray/datetime.c5
-rw-r--r--numpy/core/tests/test_datetime.py10
2 files changed, 13 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/datetime.c b/numpy/core/src/multiarray/datetime.c
index 850c92b44..cd52756b9 100644
--- a/numpy/core/src/multiarray/datetime.c
+++ b/numpy/core/src/multiarray/datetime.c
@@ -3047,7 +3047,7 @@ cast_timedelta_to_timedelta(PyArray_DatetimeMetaData *src_meta,
* Returns true if the object is something that is best considered
* a Datetime, false otherwise.
*/
-static npy_bool
+static NPY_GCC_NONNULL(1) npy_bool
is_any_numpy_datetime(PyObject *obj)
{
return (PyArray_IsScalar(obj, Datetime) ||
@@ -3296,7 +3296,8 @@ datetime_arange(PyObject *start, PyObject *stop, PyObject *step,
}
}
else {
- if (is_any_numpy_datetime(start) || is_any_numpy_datetime(stop)) {
+ if ((start && is_any_numpy_datetime(start)) ||
+ is_any_numpy_datetime(stop)) {
type_nums[0] = NPY_DATETIME;
}
else {
diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py
index bf0ba6807..4e432f885 100644
--- a/numpy/core/tests/test_datetime.py
+++ b/numpy/core/tests/test_datetime.py
@@ -1412,6 +1412,11 @@ class TestDateTime(TestCase):
np.datetime64('2012-02-03T14Z', 's'),
np.timedelta64(5, 'Y'))
+ def test_datetime_arange_no_dtype(self):
+ d = np.array('2010-01-04', dtype="M8[D]")
+ assert_equal(np.arange(d, d + 1), d)
+ assert_raises(ValueError, np.arange, d)
+
def test_timedelta_arange(self):
a = np.arange(3, 10, dtype='m8')
assert_equal(a.dtype, np.dtype('m8'))
@@ -1430,6 +1435,11 @@ class TestDateTime(TestCase):
assert_raises(TypeError, np.arange, np.timedelta64(0, 'Y'),
np.timedelta64(5, 'D'))
+ def test_timedelta_arange_no_dtype(self):
+ d = np.array(5, dtype="m8[D]")
+ assert_equal(np.arange(d, d + 1), d)
+ assert_raises(ValueError, np.arange, d)
+
def test_datetime_maximum_reduce(self):
a = np.array(['2010-01-02', '1999-03-14', '1833-03'], dtype='M8[D]')
assert_equal(np.maximum.reduce(a).dtype, np.dtype('M8[D]'))