summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/include/numpy/ndarraytypes.h6
-rw-r--r--numpy/core/src/multiarray/_datetime.h8
-rw-r--r--numpy/core/src/multiarray/arraytypes.c.src1
-rw-r--r--numpy/core/src/multiarray/datetime.c242
-rw-r--r--numpy/core/src/multiarray/datetime_busday.c3
-rw-r--r--numpy/core/src/multiarray/datetime_strings.c2
-rw-r--r--numpy/core/src/multiarray/datetime_strings.h1
-rw-r--r--numpy/core/src/multiarray/descriptor.c4
-rw-r--r--numpy/core/src/multiarray/dtype_transfer.c28
-rw-r--r--numpy/core/src/multiarray/scalartypes.c.src5
-rw-r--r--numpy/core/tests/test_datetime.py13
11 files changed, 38 insertions, 275 deletions
diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h
index d3e28fe93..9cca2ac12 100644
--- a/numpy/core/include/numpy/ndarraytypes.h
+++ b/numpy/core/include/numpy/ndarraytypes.h
@@ -718,7 +718,9 @@ typedef struct {
NPY_DATETIMEUNIT base;
int num;
/*
- * 'den' is unused, kept here for ABI compatibility with 1.6.
+ * 'den' and 'events are unused, kept here for ABI
+ * compatibility with 1.6.
+ *
* TODO: Remove for 2.0.
*/
int den;
@@ -732,14 +734,12 @@ typedef struct {
typedef struct {
npy_int64 year;
npy_int32 month, day, hour, min, sec, us, ps, as;
- npy_int32 event;
} npy_datetimestruct;
/* TO BE REMOVED - NOT USED INTERNALLY. */
typedef struct {
npy_int64 day;
npy_int32 sec, us, ps, as;
- npy_int32 event;
} npy_timedeltastruct;
/* TO BE REMOVED - NOT USED INTERNALLY. */
diff --git a/numpy/core/src/multiarray/_datetime.h b/numpy/core/src/multiarray/_datetime.h
index 41e691974..3c216d856 100644
--- a/numpy/core/src/multiarray/_datetime.h
+++ b/numpy/core/src/multiarray/_datetime.h
@@ -173,11 +173,7 @@ compute_datetime_metadata_greatest_common_divisor_capsule(
/*
* Computes the conversion factor to convert data with 'src_meta' metadata
- * into data with 'dst_meta' metadata, not taking into account the events.
- *
- * To convert a npy_datetime or npy_timedelta, first the event number needs
- * to be divided away, then it needs to be scaled by num/denom, and
- * finally the event number can be added back in.
+ * into data with 'dst_meta' metadata.
*
* If overflow occurs, both out_num and out_denom are set to 0, but
* no error is set.
@@ -231,7 +227,7 @@ convert_pyobject_to_datetime_metadata(PyObject *obj,
* 'ret' is a PyUString containing the datetime string, and this
* function appends the metadata string to it.
*
- * If 'skip_brackets' is true, skips the '[]' when events == 1.
+ * If 'skip_brackets' is true, skips the '[]'.
*
* This function steals the reference 'ret'
*/
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src
index dfcea7ef3..b27c7e43f 100644
--- a/numpy/core/src/multiarray/arraytypes.c.src
+++ b/numpy/core/src/multiarray/arraytypes.c.src
@@ -3438,7 +3438,6 @@ _init_datetime_descr(PyArray_Descr *descr)
dt_data = PyArray_malloc(sizeof(PyArray_DatetimeMetaData));
dt_data->base = NPY_DATETIME_DEFAULTUNIT;
dt_data->num = 1;
- dt_data->events = 1;
/* FIXME
* There is no error check here and no way to indicate an error
diff --git a/numpy/core/src/multiarray/datetime.c b/numpy/core/src/multiarray/datetime.c
index 019a6386f..278cbe94b 100644
--- a/numpy/core/src/multiarray/datetime.c
+++ b/numpy/core/src/multiarray/datetime.c
@@ -264,13 +264,6 @@ convert_datetimestruct_to_datetime(PyArray_DatetimeMetaData *meta,
return -1;
}
- if (dts->event < 0 || dts->event >= meta->events) {
- PyErr_Format(PyExc_ValueError,
- "NumPy datetime event %d is outside range [0,%d)",
- (int)dts->event, (int)meta->events);
- return -1;
- }
-
if (base == NPY_FR_Y) {
/* Truncate to the year */
ret = dts->year - 1970;
@@ -379,12 +372,6 @@ convert_datetimestruct_to_datetime(PyArray_DatetimeMetaData *meta,
}
}
- /* Add in the event number if needed */
- if (meta->events > 1) {
- /* Multiply by the number of events and put in the event number */
- ret = ret * meta->events + dts->event;
- }
-
*out = ret;
return 0;
@@ -404,7 +391,6 @@ PyArray_DatetimeStructToDatetime(NPY_DATETIMEUNIT fr, npy_datetimestruct *d)
/* Set up a dummy metadata for the conversion */
meta.base = fr;
meta.num = 1;
- meta.events = 1;
if (convert_datetimestruct_to_datetime(&meta, d, &ret) < 0) {
/* The caller then needs to check PyErr_Occurred() */
@@ -536,16 +522,6 @@ convert_datetime_to_datetimestruct(PyArray_DatetimeMetaData *meta,
return -1;
}
- /* Extract the event number */
- if (meta->events > 1) {
- out->event = dt % meta->events;
- dt = dt / meta->events;
- if (out->event < 0) {
- out->event += meta->events;
- --dt;
- }
- }
-
/* TODO: Change to a mechanism that avoids the potential overflow */
dt *= meta->num;
@@ -771,7 +747,6 @@ PyArray_DatetimeToDatetimeStruct(npy_datetime val, NPY_DATETIMEUNIT fr,
/* Set up a dummy metadata for the conversion */
meta.base = fr;
meta.num = 1;
- meta.events = 1;
if (convert_datetime_to_datetimestruct(&meta, val, result) < 0) {
/* The caller needs to check PyErr_Occurred() */
@@ -998,7 +973,6 @@ create_datetime_dtype_with_unit(int type_num, NPY_DATETIMEUNIT unit)
PyArray_DatetimeMetaData meta;
meta.base = unit;
meta.num = 1;
- meta.events = 1;
return create_datetime_dtype(type_num, &meta);
}
@@ -1148,7 +1122,6 @@ parse_datetime_metadata_from_metastr(char *metastr, Py_ssize_t len,
if (len == 0) {
out_meta->base = NPY_FR_GENERIC;
out_meta->num = 1;
- out_meta->events = 1;
return 0;
}
@@ -1159,10 +1132,10 @@ parse_datetime_metadata_from_metastr(char *metastr, Py_ssize_t len,
}
substrend = substr;
- while (*substrend != '\0' && *substrend != ']') {
+ while (substrend - metastr < len && *substrend != ']') {
++substrend;
}
- if (*substrend == '\0' || substr == substrend) {
+ if (substrend - metastr == len || substr == substrend) {
substr = substrend;
goto bad_input;
}
@@ -1175,21 +1148,9 @@ parse_datetime_metadata_from_metastr(char *metastr, Py_ssize_t len,
substr = substrend+1;
- /* Finally comes an optional number of events */
- if (substr[0] == '/' && substr[1] == '/') {
- substr += 2;
-
- out_meta->events = (int)strtol(substr, &substrend, 10);
- if (substr == substrend || *substrend != '\0') {
- goto bad_input;
- }
- }
- else if (*substr != '\0') {
+ if (substr - metastr != len) {
goto bad_input;
}
- else {
- out_meta->events = 1;
- }
return 0;
@@ -1432,11 +1393,7 @@ _uint64_euclidean_gcd(npy_uint64 x, npy_uint64 y)
/*
* Computes the conversion factor to convert data with 'src_meta' metadata
- * into data with 'dst_meta' metadata, not taking into account the events.
- *
- * To convert a npy_datetime or npy_timedelta, first the event number needs
- * to be divided away, then it needs to be scaled by num/denom, and
- * finally the event number can be added back in.
+ * into data with 'dst_meta' metadata.
*
* If overflow occurs, both out_num and out_denom are set to 0, but
* no error is set.
@@ -1567,11 +1524,6 @@ datetime_metadata_divides(
return 0;
}
- /* Events must match */
- if (dividend->events != divisor->events) {
- return 0;
- }
-
num1 = (npy_uint64)dividend->num;
num2 = (npy_uint64)divisor->num;
@@ -1762,8 +1714,7 @@ can_cast_datetime64_metadata(PyArray_DatetimeMetaData *src_meta,
default:
return src_meta->base == dst_meta->base &&
- src_meta->num == dst_meta->num &&
- src_meta->events == dst_meta->events;
+ src_meta->num == dst_meta->num;
}
}
@@ -1790,8 +1741,7 @@ can_cast_timedelta64_metadata(PyArray_DatetimeMetaData *src_meta,
default:
return src_meta->base == dst_meta->base &&
- src_meta->num == dst_meta->num &&
- src_meta->events == dst_meta->events;
+ src_meta->num == dst_meta->num;
}
}
@@ -1876,7 +1826,6 @@ compute_datetime_metadata_greatest_common_divisor(
{
NPY_DATETIMEUNIT base;
npy_uint64 num1, num2, num;
- int events = 1;
/* If either unit is generic, adopt the metadata from the other one */
if (meta1->base == NPY_FR_GENERIC) {
@@ -1888,14 +1837,6 @@ compute_datetime_metadata_greatest_common_divisor(
return 0;
}
- /* Take the maximum of the events */
- if (meta1->events > meta2->events) {
- events = meta1->events;
- }
- else {
- events = meta2->events;
- }
-
num1 = (npy_uint64)meta1->num;
num2 = (npy_uint64)meta2->num;
@@ -1980,7 +1921,6 @@ compute_datetime_metadata_greatest_common_divisor(
if (out_meta->num <= 0 || num != (npy_uint64)out_meta->num) {
goto units_overflow;
}
- out_meta->events = events;
return 0;
@@ -2197,7 +2137,7 @@ convert_datetime_metadata_to_tuple(PyArray_DatetimeMetaData *meta)
{
PyObject *dt_tuple;
- dt_tuple = PyTuple_New(3);
+ dt_tuple = PyTuple_New(2);
if (dt_tuple == NULL) {
return NULL;
}
@@ -2206,8 +2146,6 @@ convert_datetime_metadata_to_tuple(PyArray_DatetimeMetaData *meta)
PyBytes_FromString(_datetime_strings[meta->base]));
PyTuple_SET_ITEM(dt_tuple, 1,
PyInt_FromLong(meta->num));
- PyTuple_SET_ITEM(dt_tuple, 2,
- PyInt_FromLong(meta->events));
return dt_tuple;
}
@@ -2234,9 +2172,9 @@ convert_datetime_metadata_tuple_to_datetime_metadata(PyObject *tuple,
}
tuple_size = PyTuple_GET_SIZE(tuple);
- if (tuple_size < 3 || tuple_size > 4) {
+ if (tuple_size < 2 || tuple_size > 4) {
PyErr_SetString(PyExc_TypeError,
- "Require tuple of size 3 or 4 for "
+ "Require tuple of size 2 to 4 for "
"tuple to NumPy datetime metadata conversion");
return -1;
}
@@ -2257,24 +2195,14 @@ convert_datetime_metadata_tuple_to_datetime_metadata(PyObject *tuple,
return -1;
}
- if (tuple_size == 3) {
- out_meta->events = PyInt_AsLong(PyTuple_GET_ITEM(tuple, 2));
- if (out_meta->events == -1 && PyErr_Occurred()) {
- return -1;
- }
- }
- else {
+ if (tuple_size == 4) {
den = PyInt_AsLong(PyTuple_GET_ITEM(tuple, 2));
if (den == -1 && PyErr_Occurred()) {
return -1;
}
- out_meta->events = PyInt_AsLong(PyTuple_GET_ITEM(tuple, 3));
- if (out_meta->events == -1 && PyErr_Occurred()) {
- return -1;
- }
}
- if (out_meta->num <= 0 || out_meta->events <= 0 || den <= 0) {
+ if (out_meta->num <= 0 || den <= 0) {
PyErr_SetString(PyExc_TypeError,
"Invalid tuple values for "
"tuple to NumPy datetime metadata conversion");
@@ -2359,9 +2287,6 @@ convert_pyobject_to_datetime_metadata(PyObject *obj,
return -1;
}
- /* extended_unit is only 'num' and 'base', we have to fill the rest */
- out_meta->events = 1;
-
return 0;
}
@@ -2371,7 +2296,7 @@ convert_pyobject_to_datetime_metadata(PyObject *obj,
* 'ret' is a PyUString containing the datetime string, and this
* function appends the metadata string to it.
*
- * If 'skip_brackets' is true, skips the '[]' when events == 1.
+ * If 'skip_brackets' is true, skips the '[]'.
*
* This function steals the reference 'ret'
*/
@@ -2381,7 +2306,7 @@ append_metastr_to_string(PyArray_DatetimeMetaData *meta,
PyObject *ret)
{
PyObject *res;
- int num, events;
+ int num;
char *basestr;
if (ret == NULL) {
@@ -2401,7 +2326,6 @@ append_metastr_to_string(PyArray_DatetimeMetaData *meta,
}
num = meta->num;
- events = meta->events;
if (meta->base >= 0 && meta->base < NPY_DATETIME_NUMUNITS) {
basestr = _datetime_strings[meta->base];
}
@@ -2412,7 +2336,7 @@ append_metastr_to_string(PyArray_DatetimeMetaData *meta,
}
if (num == 1) {
- if (skip_brackets && events == 1) {
+ if (skip_brackets) {
res = PyUString_FromFormat("%s", basestr);
}
else {
@@ -2420,7 +2344,7 @@ append_metastr_to_string(PyArray_DatetimeMetaData *meta,
}
}
else {
- if (skip_brackets && events == 1) {
+ if (skip_brackets) {
res = PyUString_FromFormat("%d%s", num, basestr);
}
else {
@@ -2428,10 +2352,6 @@ append_metastr_to_string(PyArray_DatetimeMetaData *meta,
}
}
- if (events != 1) {
- PyUString_ConcatAndDel(&res,
- PyUString_FromFormat("//%d", events));
- }
PyUString_ConcatAndDel(&ret, res);
return ret;
}
@@ -2821,7 +2741,6 @@ convert_pyobject_to_datetime(PyArray_DatetimeMetaData *meta, PyObject *obj,
if (meta->base == -1) {
meta->base = bestunit;
meta->num = 1;
- meta->events = 1;
}
if (convert_datetimestruct_to_datetime(meta, &dts, out) < 0) {
@@ -2841,31 +2760,6 @@ convert_pyobject_to_datetime(PyArray_DatetimeMetaData *meta, PyObject *obj,
*out = PyLong_AsLongLong(obj);
return 0;
}
- /* Could be a tuple with event number in the second entry */
- else if (PyTuple_Check(obj) && PyTuple_Size(obj) == 2) {
- int event, event_old;
- if (convert_pyobject_to_datetime(meta, PyTuple_GET_ITEM(obj, 0),
- casting, out) < 0) {
- return -1;
- }
- event = (int)PyInt_AsLong(PyTuple_GET_ITEM(obj, 1));
- if (event == -1 && PyErr_Occurred()) {
- return -1;
- }
- if (event < 0 || event >= meta->events) {
- PyErr_SetString(PyExc_ValueError, "event value for NumPy "
- "datetime is out of range");
- return -1;
- }
- /* Replace the event with the one from the tuple */
- event_old = *out % meta->events;
- if (event_old < 0) {
- event_old += meta->events;
- }
- *out = *out - event_old + event;
-
- return 0;
- }
/* Datetime scalar */
else if (PyArray_IsScalar(obj, Datetime)) {
PyDatetimeScalarObject *dts = (PyDatetimeScalarObject *)obj;
@@ -2944,13 +2838,11 @@ convert_pyobject_to_datetime(PyArray_DatetimeMetaData *meta, PyObject *obj,
if (meta->base == -1) {
meta->base = bestunit;
meta->num = 1;
- meta->events = 1;
}
else {
PyArray_DatetimeMetaData obj_meta;
obj_meta.base = bestunit;
obj_meta.num = 1;
- obj_meta.events = 1;
if (raise_if_datetime64_metadata_cast_error(
bestunit == NPY_FR_D ? "datetime.date object"
@@ -2973,7 +2865,6 @@ convert_pyobject_to_datetime(PyArray_DatetimeMetaData *meta, PyObject *obj,
if (meta->base == -1) {
meta->base = NPY_FR_GENERIC;
meta->num = 1;
- meta->events = 1;
}
*out = NPY_DATETIME_NAT;
return 0;
@@ -3049,7 +2940,6 @@ convert_pyobject_to_timedelta(PyArray_DatetimeMetaData *meta, PyObject *obj,
if (meta->base == -1) {
meta->base = NPY_FR_GENERIC;
meta->num = 1;
- meta->events = 1;
}
return 0;
@@ -3061,7 +2951,6 @@ convert_pyobject_to_timedelta(PyArray_DatetimeMetaData *meta, PyObject *obj,
if (meta->base == -1) {
meta->base = NPY_DATETIME_DEFAULTUNIT;
meta->num = 1;
- meta->events = 1;
}
*out = PyLong_AsLongLong(obj);
@@ -3182,7 +3071,6 @@ convert_pyobject_to_timedelta(PyArray_DatetimeMetaData *meta, PyObject *obj,
if (meta->base == -1) {
meta->base = NPY_FR_us;
meta->num = 1;
- meta->events = 1;
*out = td;
@@ -3213,7 +3101,6 @@ convert_pyobject_to_timedelta(PyArray_DatetimeMetaData *meta, PyObject *obj,
us_meta.base = NPY_FR_W;
}
us_meta.num = 1;
- us_meta.events = 1;
if (raise_if_timedelta64_metadata_cast_error(
"datetime.timedelta object",
@@ -3238,7 +3125,6 @@ convert_pyobject_to_timedelta(PyArray_DatetimeMetaData *meta, PyObject *obj,
if (meta->base == -1) {
meta->base = NPY_FR_GENERIC;
meta->num = 1;
- meta->events = 1;
}
*out = NPY_DATETIME_NAT;
return 0;
@@ -3275,7 +3161,6 @@ convert_datetime_to_pyobject(npy_datetime dt, PyArray_DatetimeMetaData *meta)
/* If the type's precision is greater than microseconds, return an int */
if (meta->base > NPY_FR_us) {
- /* Skip use of a tuple for the events, just return the raw int */
return PyLong_FromLongLong(dt);
}
@@ -3290,7 +3175,6 @@ convert_datetime_to_pyobject(npy_datetime dt, PyArray_DatetimeMetaData *meta)
* return a raw int.
*/
if (dts.year < 1 || dts.year > 9999 || dts.sec == 60) {
- /* Also skip use of a tuple for the events */
return PyLong_FromLongLong(dt);
}
@@ -3304,28 +3188,7 @@ convert_datetime_to_pyobject(npy_datetime dt, PyArray_DatetimeMetaData *meta)
ret = PyDate_FromDate(dts.year, dts.month, dts.day);
}
- /* If there is one event, just return the datetime */
- if (meta->events == 1) {
- return ret;
- }
- /* Otherwise return a tuple with the event in the second position */
- else {
- tup = PyTuple_New(2);
- if (tup == NULL) {
- Py_DECREF(ret);
- return NULL;
- }
- PyTuple_SET_ITEM(tup, 0, ret);
-
- ret = PyInt_FromLong(dts.event);
- if (ret == NULL) {
- Py_DECREF(tup);
- return NULL;
- }
- PyTuple_SET_ITEM(tup, 1, ret);
-
- return tup;
- }
+ return ret;
}
/*
@@ -3340,7 +3203,6 @@ convert_timedelta_to_pyobject(npy_timedelta td, PyArray_DatetimeMetaData *meta)
{
PyObject *ret = NULL, *tup = NULL;
npy_timedelta value;
- int event = 0;
int days = 0, seconds = 0, useconds = 0;
/*
@@ -3359,22 +3221,11 @@ convert_timedelta_to_pyobject(npy_timedelta td, PyArray_DatetimeMetaData *meta)
meta->base == NPY_FR_Y ||
meta->base == NPY_FR_M ||
meta->base == NPY_FR_GENERIC) {
- /* Skip use of a tuple for the events, just return the raw int */
return PyLong_FromLongLong(td);
}
value = td;
- /* If there are events, extract the event */
- if (meta->events > 1) {
- event = (int)(value % meta->events);
- value = value / meta->events;
- if (event < 0) {
- --value;
- event += meta->events;
- }
- }
-
/* Apply the unit multiplier (TODO: overflow treatment...) */
value *= meta->num;
@@ -3428,28 +3279,7 @@ convert_timedelta_to_pyobject(npy_timedelta td, PyArray_DatetimeMetaData *meta)
}
}
- /* If there is one event, just return the datetime */
- if (meta->events == 1) {
- return ret;
- }
- /* Otherwise return a tuple with the event in the second position */
- else {
- tup = PyTuple_New(2);
- if (tup == NULL) {
- Py_DECREF(ret);
- return NULL;
- }
- PyTuple_SET_ITEM(tup, 0, ret);
-
- ret = PyInt_FromLong(event);
- if (ret == NULL) {
- Py_DECREF(tup);
- return NULL;
- }
- PyTuple_SET_ITEM(tup, 1, ret);
-
- return tup;
- }
+ return ret;
}
/*
@@ -3478,14 +3308,13 @@ has_equivalent_datetime_metadata(PyArray_Descr *type1, PyArray_Descr *type2)
return 0;
}
- /* For generic units, the num and events are ignored */
+ /* For generic units, the num is ignored */
if (meta1->base == NPY_FR_GENERIC && meta2->base == NPY_FR_GENERIC) {
return 1;
}
return meta1->base == meta2->base &&
- meta1->num == meta2->num &&
- meta1->events == meta2->events;
+ meta1->num == meta2->num;
}
/*
@@ -3504,8 +3333,7 @@ cast_datetime_to_datetime(PyArray_DatetimeMetaData *src_meta,
/* If the metadata is the same, short-circuit the conversion */
if (src_meta->base == dst_meta->base &&
- src_meta->num == dst_meta->num &&
- src_meta->events == dst_meta->events) {
+ src_meta->num == dst_meta->num) {
*dst_dt = src_dt;
return 0;
}
@@ -3515,9 +3343,6 @@ cast_datetime_to_datetime(PyArray_DatetimeMetaData *src_meta,
*dst_dt = NPY_DATETIME_NAT;
return -1;
}
- if (dts.event >= dst_meta->events) {
- dts.event = dts.event % dst_meta->events;
- }
if (convert_datetimestruct_to_datetime(dst_meta, &dts, dst_dt) < 0) {
*dst_dt = NPY_DATETIME_NAT;
return -1;
@@ -3539,12 +3364,10 @@ cast_timedelta_to_timedelta(PyArray_DatetimeMetaData *src_meta,
npy_timedelta *dst_dt)
{
npy_int64 num = 0, denom = 0;
- int event = 0;
/* If the metadata is the same, short-circuit the conversion */
if (src_meta->base == dst_meta->base &&
- src_meta->num == dst_meta->num &&
- src_meta->events == dst_meta->events) {
+ src_meta->num == dst_meta->num) {
*dst_dt = src_dt;
return 0;
}
@@ -3556,16 +3379,6 @@ cast_timedelta_to_timedelta(PyArray_DatetimeMetaData *src_meta,
return -1;
}
- /* Remove the event number from the value */
- if (src_meta->events > 1) {
- event = (int)(src_dt % src_meta->events);
- src_dt = src_dt / src_meta->events;
- if (event < 0) {
- --src_dt;
- event += src_meta->events;
- }
- }
-
/* Apply the scaling */
if (src_dt < 0) {
*dst_dt = (src_dt * num - (denom - 1)) / denom;
@@ -3574,12 +3387,6 @@ cast_timedelta_to_timedelta(PyArray_DatetimeMetaData *src_meta,
*dst_dt = src_dt * num / denom;
}
- /* Add the event number back in */
- if (dst_meta->events > 1) {
- event = event % dst_meta->events;
- *dst_dt = (*dst_dt) * dst_meta->events + event;
- }
-
return 0;
}
@@ -3662,7 +3469,6 @@ convert_pyobjects_to_datetimes(int count,
for (i = 0; i < count; ++i) {
meta[i].base = -1;
meta[i].num = 1;
- meta[i].events = 1;
/* NULL -> NaT */
if (objs[i] == NULL) {
@@ -4047,7 +3853,6 @@ find_string_array_datetime64_type(PyObject *obj,
}
tmp_meta.num = 1;
- tmp_meta.events = 1;
/* Combine it with 'meta' */
if (compute_datetime_metadata_greatest_common_divisor(meta,
&tmp_meta, meta, 0, 0) < 0) {
@@ -4136,7 +3941,6 @@ recursive_find_object_datetime64_type(PyObject *obj,
tmp_meta.base = -1;
tmp_meta.num = 1;
- tmp_meta.events = 1;
if (convert_pyobject_to_datetime(&tmp_meta, obj,
NPY_UNSAFE_CASTING, &tmp) < 0) {
@@ -4167,7 +3971,6 @@ recursive_find_object_datetime64_type(PyObject *obj,
tmp_meta.base = NPY_FR_D;
tmp_meta.num = 1;
- tmp_meta.events = 1;
/* Combine it with 'meta' */
if (compute_datetime_metadata_greatest_common_divisor(meta,
@@ -4183,7 +3986,6 @@ recursive_find_object_datetime64_type(PyObject *obj,
tmp_meta.base = NPY_FR_us;
tmp_meta.num = 1;
- tmp_meta.events = 1;
/* Combine it with 'meta' */
if (compute_datetime_metadata_greatest_common_divisor(meta,
@@ -4285,7 +4087,6 @@ recursive_find_object_timedelta64_type(PyObject *obj,
tmp_meta.base = NPY_FR_us;
tmp_meta.num = 1;
- tmp_meta.events = 1;
/* Combine it with 'meta' */
if (compute_datetime_metadata_greatest_common_divisor(meta,
@@ -4339,7 +4140,6 @@ find_object_datetime_type(PyObject *obj, int type_num)
meta.base = NPY_FR_GENERIC;
meta.num = 1;
- meta.events = 1;
if (type_num == NPY_DATETIME) {
if (recursive_find_object_datetime64_type(obj, &meta) < 0) {
diff --git a/numpy/core/src/multiarray/datetime_busday.c b/numpy/core/src/multiarray/datetime_busday.c
index 2d83786a6..67e403cf7 100644
--- a/numpy/core/src/multiarray/datetime_busday.c
+++ b/numpy/core/src/multiarray/datetime_busday.c
@@ -465,7 +465,6 @@ business_day_offset(PyArrayObject *dates, PyArrayObject *offsets,
/* First create the data types for dates and offsets */
temp_meta.base = NPY_FR_D;
temp_meta.num = 1;
- temp_meta.events = 1;
dtypes[0] = create_datetime_dtype(NPY_DATETIME, &temp_meta);
if (dtypes[0] == NULL) {
goto fail;
@@ -599,7 +598,6 @@ business_day_count(PyArrayObject *dates_begin, PyArrayObject *dates_end,
/* First create the data types for the dates and the int64 output */
temp_meta.base = NPY_FR_D;
temp_meta.num = 1;
- temp_meta.events = 1;
dtypes[0] = create_datetime_dtype(NPY_DATETIME, &temp_meta);
if (dtypes[0] == NULL) {
goto fail;
@@ -730,7 +728,6 @@ is_business_day(PyArrayObject *dates, PyArrayObject *out,
/* First create the data types for the dates and the bool output */
temp_meta.base = NPY_FR_D;
temp_meta.num = 1;
- temp_meta.events = 1;
dtypes[0] = create_datetime_dtype(NPY_DATETIME, &temp_meta);
if (dtypes[0] == NULL) {
goto fail;
diff --git a/numpy/core/src/multiarray/datetime_strings.c b/numpy/core/src/multiarray/datetime_strings.c
index 4b5395d89..46e9db56d 100644
--- a/numpy/core/src/multiarray/datetime_strings.c
+++ b/numpy/core/src/multiarray/datetime_strings.c
@@ -26,7 +26,6 @@
/*
* Parses (almost) standard ISO 8601 date strings. The differences are:
*
- * + After the date and time, may place a ' ' followed by an event number.
* + The date "20100312" is parsed as the year 20100312, not as
* equivalent to "2010-03-12". The '-' in the dates are not optional.
* + Only seconds may have a decimal point, with up to 18 digits after it
@@ -184,7 +183,6 @@ parse_iso_8601_datetime(char *str, int len,
/* Set up a dummy metadata for the conversion */
meta.base = NPY_FR_s;
meta.num = 1;
- meta.events = 1;
bestunit = NPY_FR_s;
diff --git a/numpy/core/src/multiarray/datetime_strings.h b/numpy/core/src/multiarray/datetime_strings.h
index e855a8631..e1d96b125 100644
--- a/numpy/core/src/multiarray/datetime_strings.h
+++ b/numpy/core/src/multiarray/datetime_strings.h
@@ -4,7 +4,6 @@
/*
* Parses (almost) standard ISO 8601 date strings. The differences are:
*
- * + After the date and time, may place a ' ' followed by an event number.
* + The date "20100312" is parsed as the year 20100312, not as
* equivalent to "2010-03-12". The '-' in the dates are not optional.
* + Only seconds may have a decimal point, with up to 18 digits after it
diff --git a/numpy/core/src/multiarray/descriptor.c b/numpy/core/src/multiarray/descriptor.c
index 601691711..2e793fe1f 100644
--- a/numpy/core/src/multiarray/descriptor.c
+++ b/numpy/core/src/multiarray/descriptor.c
@@ -1793,7 +1793,7 @@ arraydescr_new(PyTypeObject *NPY_UNUSED(subtype), PyObject *args, PyObject *kwds
/*
* Return a tuple of
- * (cleaned metadata dictionary, tuple with (str, num, events))
+ * (cleaned metadata dictionary, tuple with (str, num))
*/
static PyObject *
_get_pickleabletype_from_datetime_metadata(PyArray_Descr *dtype)
@@ -1904,7 +1904,7 @@ arraydescr_reduce(PyArray_Descr *self, PyObject *NPY_UNUSED(args))
/* Handle CObject in NPY_METADATA_DTSTR key separately */
/*
* newobj is a tuple of cleaned metadata dictionary
- * and tuple of date_time info (str, num, den, events)
+ * and tuple of date_time info (str, num)
*/
newobj = _get_pickleabletype_from_datetime_metadata(self);
if (newobj == NULL) {
diff --git a/numpy/core/src/multiarray/dtype_transfer.c b/numpy/core/src/multiarray/dtype_transfer.c
index fa5573ad5..c17593afe 100644
--- a/numpy/core/src/multiarray/dtype_transfer.c
+++ b/numpy/core/src/multiarray/dtype_transfer.c
@@ -705,8 +705,6 @@ typedef struct {
copy_strided_transfer_data copyfunc;
/* The conversion fraction */
npy_int64 num, denom;
- /* The number of events in the source and destination */
- int src_events, dst_events;
/*
* The metadata for when dealing with Months or Years
* which behave non-linearly with respect to the other
@@ -748,7 +746,6 @@ _strided_to_strided_datetime_general_cast(char *dst, npy_intp dst_stride,
dt = NPY_DATETIME_NAT;
}
else {
- dts.event = dts.event % d->dst_meta.events;
if (convert_datetimestruct_to_datetime(&d->dst_meta,
&dts, &dt) < 0) {
dt = NPY_DATETIME_NAT;
@@ -772,22 +769,11 @@ _strided_to_strided_datetime_cast(char *dst, npy_intp dst_stride,
_strided_datetime_cast_data *d = (_strided_datetime_cast_data *)data;
npy_int64 num = d->num, denom = d->denom;
npy_int64 dt;
- int event = 0, src_events = d->src_events, dst_events = d->dst_events;
while (N > 0) {
memcpy(&dt, src, sizeof(dt));
if (dt != NPY_DATETIME_NAT) {
- /* Remove the event number from the value */
- if (src_events > 1) {
- event = (int)(dt % src_events);
- dt = dt / src_events;
- if (event < 0) {
- --dt;
- event += src_events;
- }
- }
-
/* Apply the scaling */
if (dt < 0) {
dt = (dt * num - (denom - 1)) / denom;
@@ -795,12 +781,6 @@ _strided_to_strided_datetime_cast(char *dst, npy_intp dst_stride,
else {
dt = dt * num / denom;
}
-
- /* Add the event number back in */
- if (dst_events > 1) {
- event = event % dst_events;
- dt = dt * dst_events + event;
- }
}
memcpy(dst, &dt, sizeof(dt));
@@ -812,7 +792,7 @@ _strided_to_strided_datetime_cast(char *dst, npy_intp dst_stride,
}
static void
-_aligned_strided_to_strided_datetime_cast_no_events(char *dst,
+_aligned_strided_to_strided_datetime_cast(char *dst,
npy_intp dst_stride,
char *src, npy_intp src_stride,
npy_intp N, npy_intp src_itemsize,
@@ -885,8 +865,6 @@ get_nbo_cast_datetime_transfer_function(int aligned,
data->copyfunc = &_strided_datetime_cast_data_copy;
data->num = num;
data->denom = denom;
- data->src_events = src_meta->events;
- data->dst_events = dst_meta->events;
/*
* Special case the datetime (but not timedelta) with the nonlinear
@@ -902,8 +880,8 @@ get_nbo_cast_datetime_transfer_function(int aligned,
memcpy(&data->dst_meta, dst_meta, sizeof(data->dst_meta));
*out_stransfer = &_strided_to_strided_datetime_general_cast;
}
- else if (aligned && data->src_events == 1 && data->dst_events == 1) {
- *out_stransfer = &_aligned_strided_to_strided_datetime_cast_no_events;
+ else if (aligned) {
+ *out_stransfer = &_aligned_strided_to_strided_datetime_cast;
}
else {
*out_stransfer = &_strided_to_strided_datetime_cast;
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src
index 7f46cd1ec..21d8804b7 100644
--- a/numpy/core/src/multiarray/scalartypes.c.src
+++ b/numpy/core/src/multiarray/scalartypes.c.src
@@ -630,7 +630,7 @@ datetimetype_repr(PyObject *self)
* For straight units or generic units, the unit will be deduced
* from the string, so it's not necessary to specify it.
*/
- if ((scal->obmeta.num == 1 && scal->obmeta.events == 1) ||
+ if ((scal->obmeta.num == 1) ||
scal->obmeta.base == NPY_FR_GENERIC) {
ret = PyUString_FromString("numpy.datetime64('");
PyUString_ConcatAndDel(&ret,
@@ -751,8 +751,6 @@ timedeltatype_str(PyObject *self)
scal = (PyTimedeltaScalarObject *)self;
- /* TODO: Account for events, etc */
-
if (scal->obmeta.base >= 0 && scal->obmeta.base < NPY_DATETIME_NUMUNITS) {
basestr = _datetime_verbose_strings[scal->obmeta.base];
}
@@ -2570,7 +2568,6 @@ static PyObject *
if (ret->obmeta.base == -1) {
ret->obmeta.base = NPY_DATETIME_DEFAULTUNIT;
ret->obmeta.num = 1;
- ret->obmeta.events = 1;
}
/* Make datetime default to NaT, timedelta default to zero */
diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py
index 587f32092..310b8be76 100644
--- a/numpy/core/tests/test_datetime.py
+++ b/numpy/core/tests/test_datetime.py
@@ -425,7 +425,6 @@ class TestDateTime(TestCase):
assert_(np.dtype('M8[us]') != np.dtype('M8[ms]'))
assert_(np.dtype('M8[2D]') != np.dtype('M8[D]'))
assert_(np.dtype('M8[D]') != np.dtype('M8[2D]'))
- assert_(np.dtype('M8[Y]//3') != np.dtype('M8[Y]'))
def test_pydatetime_creation(self):
a = np.array(['1960-03-12', datetime.date(1960, 3, 12)], dtype='M8[D]')
@@ -447,7 +446,7 @@ class TestDateTime(TestCase):
def test_pickle(self):
# Check that pickle roundtripping works
- dt = np.dtype('M8[7D]//3')
+ dt = np.dtype('M8[7D]')
assert_equal(dt, pickle.loads(pickle.dumps(dt)))
dt = np.dtype('M8[W]')
assert_equal(dt, pickle.loads(pickle.dumps(dt)))
@@ -492,7 +491,7 @@ class TestDateTime(TestCase):
-1020040340, -2942398, -1, 0, 1, 234523453, 1199164176],
dtype=np.int64)
# With date units
- for unit in ['M8[D]', 'M8[D]//4', 'M8[W]', 'M8[M]', 'M8[Y]']:
+ for unit in ['M8[D]', 'M8[W]', 'M8[M]', 'M8[Y]']:
b = a.copy().view(dtype=unit)
b[0] = '-0001-01-01'
b[1] = '-0001-12-31'
@@ -508,7 +507,7 @@ class TestDateTime(TestCase):
"Error roundtripping unit %s" % unit)
# With time units
for unit in ['M8[as]', 'M8[16fs]', 'M8[ps]', 'M8[us]',
- 'M8[as]//12', 'M8[us]//16']:
+ 'M8[300as]', 'M8[20us]']:
b = a.copy().view(dtype=unit)
b[0] = '-0001-01-01T00Z'
b[1] = '-0001-12-31T00Z'
@@ -598,8 +597,8 @@ class TestDateTime(TestCase):
assert_raises(TypeError, np.less, a, b, casting='same_kind')
def test_datetime_like(self):
- a = np.array([3], dtype='m8[4D]//6')
- b = np.array(['2012-12-21'], dtype='M8[D]//3')
+ a = np.array([3], dtype='m8[4D]')
+ b = np.array(['2012-12-21'], dtype='M8[D]')
assert_equal(np.ones_like(a).dtype, a.dtype)
assert_equal(np.zeros_like(a).dtype, a.dtype)
@@ -1573,7 +1572,7 @@ class TestDateTimeData(TestCase):
def test_basic(self):
a = np.array(['1980-03-23'], dtype=np.datetime64)
- assert_equal(np.datetime_data(a.dtype), (asbytes('D'), 1, 1))
+ assert_equal(np.datetime_data(a.dtype), (asbytes('D'), 1))
if __name__ == "__main__":
run_module_suite()