Skip to content

Commit 098ce73

Browse files
committed
ENH: added additional datetime support, backporting some numpy 1.7 code
1 parent 8b71597 commit 098ce73

11 files changed

+2755
-356
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ build
55
dist
66
MANIFEST
77
*.c
8-
!datetime_helper.c
8+
!np_datetime.c
9+
!np_datetime_strings.c
910
*.cpp
1011
*.so
1112
*.pyd

pandas/core/datetools.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
import numpy as np
66
import pandas._tseries as lib
7+
import pandas._datetime as dtlib
78

89
try:
910
import dateutil
@@ -24,28 +25,26 @@
2425
#-------------------------------------------------------------------------------
2526
# Boxing and unboxing
2627

27-
# TODO: fix to use new Date boxing logic
28-
2928
_unbox_cache = dict()
3029
def _dt_unbox(key):
3130
'''
32-
Unbox datetime to datetime64
31+
Unbox python datetime to datetime64
3332
'''
3433
try:
3534
return _unbox_cache[key]
3635
except KeyError:
37-
_unbox_cache[key] = np.datetime64(key)
36+
_unbox_cache[key] = np.datetime64(dtlib.pydt_to_i8(key))
3837
return _unbox_cache[key]
3938

4039
_box_cache = dict()
4140
def _dt_box(key):
4241
'''
43-
Box datetime64 to datetime
42+
Box datetime64 to python datetime
4443
'''
4544
try:
4645
return _box_cache[key]
4746
except KeyError:
48-
_box_cache[key] = key.astype('O')
47+
_box_cache[key] = dtlib.i8_to_pydt(key.view('i8'))
4948
return _box_cache[key]
5049

5150
#-------------------------------------------------------------------------------

pandas/src/datetime.pxd

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ cdef extern from "datetime.h":
2222
int PyDateTime_TIME_GET_MICROSECOND(datetime o)
2323
bint PyDateTime_Check(object o)
2424
void PyDateTime_IMPORT()
25+
PyObject *PyDateTime_FromDateAndTime(int year, int month, int day, int hour,
26+
int minute, int second, int us)
2527

2628
cdef extern from "numpy/ndarrayobject.h":
2729

@@ -55,8 +57,10 @@ cdef extern from "numpy/ndarrayobject.h":
5557
NPY_DATETIMEUNIT fr,
5658
npy_datetimestruct *result)
5759

58-
cdef extern from "datetime_helper.h":
60+
cdef extern from "np_datetime.h":
5961

6062
int convert_pydatetime_to_datetimestruct(PyObject *obj, npy_datetimestruct *out,
6163
NPY_DATETIMEUNIT *out_bestunit,
6264
int apply_tzinfo)
65+
66+
int is_leapyear(int64_t year)

0 commit comments

Comments
 (0)