~pythonxy/pythonxy-upstream/python-pandas

« back to all changes in this revision

Viewing changes to pandas/lib/src/tdates.c

  • Committer: Wes McKinney
  • Date: 2009-08-05 03:30:16 UTC
  • Revision ID: git-v1:c6b236db73ff81007909be6406f0e484edc4a9eb
first commit with cleaned up code

git-svn-id: http://pandas.googlecode.com/svn/trunk@5 d5231056-7de3-11de-ac95-d976489f1ece

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <Python.h>
 
2
#include <datetime.h>
 
3
#include <numpy/arrayobject.h>
 
4
#include <stdio.h>
 
5
 
 
6
static PyObject* isAllDates(PyObject *self, PyObject *args) {
 
7
    PyDateTime_IMPORT;
 
8
 
 
9
    PyObject *input;
 
10
    PyArrayIterObject *iter;
 
11
    PyObject *obj;
 
12
 
 
13
 
 
14
    if (PyArg_ParseTuple(args, "O", &input)) {
 
15
        if (!PyArray_Check(input)) {
 
16
            PyErr_SetString(PyExc_RuntimeError, "Input was not ndarray!");
 
17
            return NULL;
 
18
        }
 
19
 
 
20
        long size = PyArray_SIZE(input);
 
21
    
 
22
        if (size == 0) {
 
23
            Py_RETURN_FALSE;    
 
24
        }
 
25
    
 
26
        iter = (PyArrayIterObject *) PyArray_IterNew(input);
 
27
    
 
28
        while (iter->index < iter->size) {
 
29
            obj = PyArray_GETITEM(input, (void *) iter->dataptr);
 
30
            if (!PyDateTime_Check(obj)) {
 
31
                Py_DECREF(obj);
 
32
                Py_DECREF(iter);
 
33
    
 
34
                Py_RETURN_FALSE;
 
35
            }
 
36
    
 
37
            Py_DECREF(obj);
 
38
            PyArray_ITER_NEXT(iter);
 
39
        }
 
40
    
 
41
        Py_DECREF(iter);
 
42
        Py_RETURN_TRUE;
 
43
    }   
 
44
    return NULL;
 
45
}
 
46
 
 
47
static PyMethodDef tdatesMethods[] =
 
48
{
 
49
    { "isAllDates", isAllDates, METH_VARARGS, NULL },
 
50
    {  NULL, NULL, 0, NULL},
 
51
};
 
52
 
 
53
PyMODINIT_FUNC inittdates(void)
 
54
{
 
55
    (void) Py_InitModule("tdates", tdatesMethods);
 
56
    import_array();
 
57
}