Skip to content

Commit

Permalink
ENH: added additional datetime support, backporting some numpy 1.7 code
Browse files Browse the repository at this point in the history
  • Loading branch information
adamklein committed Jan 23, 2012
1 parent 8b71597 commit 098ce73
Show file tree
Hide file tree
Showing 11 changed files with 2,755 additions and 356 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ build
dist
MANIFEST
*.c
!datetime_helper.c
!np_datetime.c
!np_datetime_strings.c
*.cpp
*.so
*.pyd
Expand Down
11 changes: 5 additions & 6 deletions pandas/core/datetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import numpy as np
import pandas._tseries as lib
import pandas._datetime as dtlib

try:
import dateutil
Expand All @@ -24,28 +25,26 @@
#-------------------------------------------------------------------------------
# Boxing and unboxing

# TODO: fix to use new Date boxing logic

_unbox_cache = dict()
def _dt_unbox(key):
'''
Unbox datetime to datetime64
Unbox python datetime to datetime64
'''
try:
return _unbox_cache[key]
except KeyError:
_unbox_cache[key] = np.datetime64(key)
_unbox_cache[key] = np.datetime64(dtlib.pydt_to_i8(key))
return _unbox_cache[key]

_box_cache = dict()
def _dt_box(key):
'''
Box datetime64 to datetime
Box datetime64 to python datetime
'''
try:
return _box_cache[key]
except KeyError:
_box_cache[key] = key.astype('O')
_box_cache[key] = dtlib.i8_to_pydt(key.view('i8'))
return _box_cache[key]

#-------------------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion pandas/src/datetime.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ cdef extern from "datetime.h":
int PyDateTime_TIME_GET_MICROSECOND(datetime o)
bint PyDateTime_Check(object o)
void PyDateTime_IMPORT()
PyObject *PyDateTime_FromDateAndTime(int year, int month, int day, int hour,
int minute, int second, int us)

cdef extern from "numpy/ndarrayobject.h":

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

cdef extern from "datetime_helper.h":
cdef extern from "np_datetime.h":

int convert_pydatetime_to_datetimestruct(PyObject *obj, npy_datetimestruct *out,
NPY_DATETIMEUNIT *out_bestunit,
int apply_tzinfo)

int is_leapyear(int64_t year)
Loading

0 comments on commit 098ce73

Please sign in to comment.