diff options
author | Travis Oliphant <oliphant@enthought.com> | 2009-08-25 22:08:10 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2009-08-25 22:08:10 +0000 |
commit | ed997cb5f3816ef60e741d3bc877d1fdcc596d07 (patch) | |
tree | 723232791db56ff55bcac326fb797be9fcb9e84d | |
parent | 885b0dd12e9ff138e964a05c299e90372c4ecd39 (diff) | |
download | numpy-ed997cb5f3816ef60e741d3bc877d1fdcc596d07.tar.gz |
Stopping for today. Pick up again tomorrow. This branch does not compile.
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 58 | ||||
-rw-r--r-- | numpy/core/src/multiarray/parse_datetime.c | 4 |
2 files changed, 55 insertions, 7 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index 8dfd429ab..195d6096f 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -145,22 +145,21 @@ static int #include "parse_datetime.c" /* End of contributed code. */ + /* DateTime Objects in Python only keep microsecond resolution. - When converting from datetime objects in nanosecond, picosecond, femtosecond, - and attosecond types return Python Longs instead. When converting from datetime objects with an event component return a tuple: - (baseunit, number of event) where baseunit follows standard and - number of event is a Python integer + (baseunit, number of event) where baseunit follows is a datetime type and + number of events is a Python integer */ - static PyObject * PyDatetime_FromInt64(datetime val, PyArray_Descr *descr) { PyArray_DatetimeMetaData *meta; PyObject *obj; meta = PyDataType_GetDatetimeMetaData(descr); + longlong normalized; if (meta->events > 1) { int events, rem, div; @@ -179,14 +178,35 @@ PyDatetime_FromInt64(datetime val, PyArray_Descr *descr) return obj; } + /* We normalize the number to a base-unit and then return either a Python Date + Object or a Python DateTime Object + + FIXME? : We silently truncate if it doesn't fit, either too big (10 BC) + or too small (nanoseconds) + */ + + /* Normalization */ + + normalize = val; + normalize + + + if (meta->base > NPY_FR_us) { /* we just return the integer itself */ return PyLong_FromLongLong((longlong) val); } + + if (meta->base < NPY_FR_D) { + /* return a Date object */ + /* The number is the number of 'FR' since EPOCH */ + + } /* otherwise, we construct a date-time object */ + } @@ -267,6 +287,31 @@ PyTimedelta_AsInt64(PyObject *obj, PyArray_Descr *descr) } } +/* Always return DateTime Object after normalizing to basic units (or a tuple + if meta->events > 1): + + Problem: DateTime does not support all the resolutions (ns) nor the dynamic + range (pre 1 AD) of NumPy Date-times. + + * getitem is not used that much --- if losing resolution hurts, stick + with the array scalar versions of the date-time. + + * considered returning array scalars here just like longdouble. + This has the problem of recursion in some cases (because in a few + places the code expects getitem to return a Python-system object) + + * considered returning different things depending on the resolution but + this would make it hard to write generic code --- + but do you need to write generic code on all the frequencies + because they cover a wide range. + + Solution: The use-case of actually wanting a date-time object when the resolution + and dynamic range match, make it the compelling default. When it + does fails, there are alternatives for the programmer to use. + + New question: Should we change (c)longdouble at this point? to return Python Float? + +*/ static PyObject * DATETIME_getitem(char *ip, PyArrayObject *ap) { @@ -426,6 +471,9 @@ static int /**end repeat**/ +/* These return array scalars which is different than other date-types. + */ + static PyObject * LONGDOUBLE_getitem(char *ip, PyArrayObject *ap) { diff --git a/numpy/core/src/multiarray/parse_datetime.c b/numpy/core/src/multiarray/parse_datetime.c index 00f824ccb..e2a2ad3c0 100644 --- a/numpy/core/src/multiarray/parse_datetime.c +++ b/numpy/core/src/multiarray/parse_datetime.c @@ -5,8 +5,8 @@ /* For defaults and errors */ #define NPY_FR_ERR -1 -/* Offset for number of days between Jan 1, 1970 and Jan 1, 0001 */ -* Assuming Gregorian calendar was always in effect +/* Offset for number of days between Jan 1, 1970 and Jan 1, 0001 +* Assuming Gregorian calendar was always in effect (proleptic Gregorian calendar) */ #define DAYS_EPOCH 719163 |