MCPcopy Create free account
hub / github.com/numpy/numpy / datetime_arange

Function datetime_arange

numpy/core/src/multiarray/datetime.c:3255–3450  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3253}
3254
3255NPY_NO_EXPORT PyArrayObject *
3256datetime_arange(PyObject *start, PyObject *stop, PyObject *step,
3257 PyArray_Descr *dtype)
3258{
3259
3260 /*
3261 * First normalize the input parameters so there is no Py_None,
3262 * and start is moved to stop if stop is unspecified.
3263 */
3264 if (step == Py_None) {
3265 step = NULL;
3266 }
3267 if (stop == NULL || stop == Py_None) {
3268 stop = start;
3269 start = NULL;
3270 /* If start was NULL or None, raise an exception */
3271 if (stop == NULL || stop == Py_None) {
3272 PyErr_SetString(PyExc_ValueError,
3273 "arange needs at least a stopping value");
3274 return NULL;
3275 }
3276 }
3277 if (start == Py_None) {
3278 start = NULL;
3279 }
3280
3281 /* Step must not be a Datetime */
3282 if (step != NULL && is_any_numpy_datetime(step)) {
3283 PyErr_SetString(PyExc_ValueError,
3284 "cannot use a datetime as a step in arange");
3285 return NULL;
3286 }
3287
3288 /* Check if the units of the given dtype are generic, in which
3289 * case we use the code path that detects the units
3290 */
3291 int type_nums[3];
3292 PyArray_DatetimeMetaData meta;
3293 if (dtype != NULL) {
3294 PyArray_DatetimeMetaData *meta_tmp;
3295
3296 type_nums[0] = dtype->type_num;
3297 if (type_nums[0] != NPY_DATETIME && type_nums[0] != NPY_TIMEDELTA) {
3298 PyErr_SetString(PyExc_ValueError,
3299 "datetime_arange was given a non-datetime dtype");
3300 return NULL;
3301 }
3302
3303 meta_tmp = get_datetime_metadata_from_dtype(dtype);
3304 if (meta_tmp == NULL) {
3305 return NULL;
3306 }
3307
3308 /*
3309 * If the dtype specified is in generic units, detect the
3310 * units from the input parameters.
3311 */
3312 if (meta_tmp->base == NPY_FR_GENERIC) {

Callers 1

PyArray_ArangeObjFunction · 0.85

Calls 6

is_any_numpy_timedeltaFunction · 0.85
create_datetime_dtypeFunction · 0.85
PyArray_NewFromDescrFunction · 0.85
PyArray_DATAFunction · 0.85

Tested by

no test coverage detected