@@ -318,26 +318,19 @@ int cmp_pandas_datetimestruct(const pandas_datetimestruct *a,
318318/* 
319319 * 
320320 * Tests for and converts a Python datetime.datetime or datetime.date 
321-  * object into a NumPy pandas_datetimestruct. 
321+  * object into a NumPy pandas_datetimestruct.  Uses tzinfo (if present) 
322+  * to convert to UTC time. 
322323 * 
323324 * While the C API has PyDate_* and PyDateTime_* functions, the following 
324325 * implementation just asks for attributes, and thus supports 
325326 * datetime duck typing. The tzinfo time zone conversion would require 
326327 * this style of access anyway. 
327328 * 
328-  * 'out_bestunit' gives a suggested unit based on whether the object 
329-  *      was a datetime.date or datetime.datetime object. 
330-  * 
331-  * If 'apply_tzinfo' is 1, this function uses the tzinfo to convert 
332-  * to UTC time, otherwise it returns the struct with the local time. 
333-  * 
334329 * Returns -1 on error, 0 on success, and 1 (with no error set) 
335330 * if obj doesn't have the neeeded date or datetime attributes. 
336331 */ 
337332int  convert_pydatetime_to_datetimestruct (PyObject  * obj ,
338-                                          pandas_datetimestruct  * out ,
339-                                          PANDAS_DATETIMEUNIT  * out_bestunit ,
340-                                          int  apply_tzinfo ) {
333+                                          pandas_datetimestruct  * out ) {
341334    PyObject  * tmp ;
342335    int  isleap ;
343336
@@ -404,10 +397,6 @@ int convert_pydatetime_to_datetimestruct(PyObject *obj,
404397        !PyObject_HasAttrString (obj , "minute" ) || 
405398        !PyObject_HasAttrString (obj , "second" ) || 
406399        !PyObject_HasAttrString (obj , "microsecond" )) {
407-         /* The best unit for date is 'D' */ 
408-         if  (out_bestunit  !=  NULL ) {
409-             * out_bestunit  =  PANDAS_FR_D ;
410-         }
411400        return  0 ;
412401    }
413402
@@ -465,7 +454,7 @@ int convert_pydatetime_to_datetimestruct(PyObject *obj,
465454    }
466455
467456    /* Apply the time zone offset if it exists */ 
468-     if  (apply_tzinfo   &&   PyObject_HasAttrString (obj , "tzinfo" )) {
457+     if  (PyObject_HasAttrString (obj , "tzinfo" )) {
469458        tmp  =  PyObject_GetAttrString (obj , "tzinfo" );
470459        if  (tmp  ==  NULL ) {
471460            return  -1 ;
@@ -506,11 +495,6 @@ int convert_pydatetime_to_datetimestruct(PyObject *obj,
506495        }
507496    }
508497
509-     /* The resolution of Python's datetime is 'us' */ 
510-     if  (out_bestunit  !=  NULL ) {
511-         * out_bestunit  =  PANDAS_FR_us ;
512-     }
513- 
514498    return  0 ;
515499
516500invalid_date :
@@ -529,51 +513,34 @@ int convert_pydatetime_to_datetimestruct(PyObject *obj,
529513
530514npy_datetime  pandas_datetimestruct_to_datetime (PANDAS_DATETIMEUNIT  fr ,
531515                                               pandas_datetimestruct  * d ) {
532-     pandas_datetime_metadata  meta ;
533516    npy_datetime  result  =  PANDAS_DATETIME_NAT ;
534517
535-     meta .base  =  fr ;
536-     meta .num  =  1 ;
537- 
538-     convert_datetimestruct_to_datetime (& meta , d , & result );
518+     convert_datetimestruct_to_datetime (fr , d , & result );
539519    return  result ;
540520}
541521
542522void  pandas_datetime_to_datetimestruct (npy_datetime  val , PANDAS_DATETIMEUNIT  fr ,
543523                                       pandas_datetimestruct  * result ) {
544-     pandas_datetime_metadata  meta ;
545- 
546-     meta .base  =  fr ;
547-     meta .num  =  1 ;
548- 
549-     convert_datetime_to_datetimestruct (& meta , val , result );
524+     convert_datetime_to_datetimestruct (fr , val , result );
550525}
551526
552527void  pandas_timedelta_to_timedeltastruct (npy_timedelta  val ,
553528                                         PANDAS_DATETIMEUNIT  fr ,
554529                                         pandas_timedeltastruct  * result ) {
555-   pandas_datetime_metadata  meta ;
556- 
557-   meta .base  =  fr ;
558-   meta .num  =  1 ;
559- 
560-   convert_timedelta_to_timedeltastruct (& meta , val , result );
530+   convert_timedelta_to_timedeltastruct (fr , val , result );
561531}
562532
563533
564534/* 
565535 * Converts a datetime from a datetimestruct to a datetime based 
566-  * on some metadata. The date is assumed to be valid. 
567-  * 
568-  * TODO: If meta->num is really big, there could be overflow 
536+  * on a metadata unit. The date is assumed to be valid. 
569537 * 
570538 * Returns 0 on success, -1 on failure. 
571539 */ 
572- int  convert_datetimestruct_to_datetime (pandas_datetime_metadata   * meta ,
540+ int  convert_datetimestruct_to_datetime (PANDAS_DATETIMEUNIT   base ,
573541                                       const  pandas_datetimestruct  * dts ,
574542                                       npy_datetime  * out ) {
575543    npy_datetime  ret ;
576-     PANDAS_DATETIMEUNIT  base  =  meta -> base ;
577544
578545    if  (base  ==  PANDAS_FR_Y ) {
579546        /* Truncate to the year */ 
@@ -665,15 +632,6 @@ int convert_datetimestruct_to_datetime(pandas_datetime_metadata *meta,
665632        }
666633    }
667634
668-     /* Divide by the multiplier */ 
669-     if  (meta -> num  >  1 ) {
670-         if  (ret  >= 0 ) {
671-             ret  /= meta -> num ;
672-         } else  {
673-             ret  =  (ret  -  meta -> num  +  1 ) / meta -> num ;
674-         }
675-     }
676- 
677635    * out  =  ret ;
678636
679637    return  0 ;
@@ -682,7 +640,7 @@ int convert_datetimestruct_to_datetime(pandas_datetime_metadata *meta,
682640/* 
683641 * Converts a datetime based on the given metadata into a datetimestruct 
684642 */ 
685- int  convert_datetime_to_datetimestruct (pandas_datetime_metadata   * meta ,
643+ int  convert_datetime_to_datetimestruct (PANDAS_DATETIMEUNIT   base ,
686644                                       npy_datetime  dt ,
687645                                       pandas_datetimestruct  * out ) {
688646    npy_int64  perday ;
@@ -693,14 +651,11 @@ int convert_datetime_to_datetimestruct(pandas_datetime_metadata *meta,
693651    out -> month  =  1 ;
694652    out -> day  =  1 ;
695653
696-     /* TODO: Change to a mechanism that avoids the potential overflow */ 
697-     dt  *= meta -> num ;
698- 
699654    /* 
700655     * Note that care must be taken with the / and % operators 
701656     * for negative values. 
702657     */ 
703-     switch  (meta -> base ) {
658+     switch  (base ) {
704659        case  PANDAS_FR_Y :
705660            out -> year  =  1970  +  dt ;
706661            break ;
@@ -902,11 +857,11 @@ int convert_datetime_to_datetimestruct(pandas_datetime_metadata *meta,
902857
903858/* 
904859 * Converts a timedelta from a timedeltastruct to a timedelta based 
905-  * on some  metadata. The timedelta is assumed to be valid. 
860+  * on a  metadata unit . The timedelta is assumed to be valid. 
906861 * 
907862 * Returns 0 on success, -1 on failure. 
908863 */ 
909- int  convert_timedelta_to_timedeltastruct (pandas_timedelta_metadata   * meta ,
864+ int  convert_timedelta_to_timedeltastruct (PANDAS_DATETIMEUNIT   base ,
910865                                         npy_timedelta  td ,
911866                                         pandas_timedeltastruct  * out ) {
912867    npy_int64  frac ;
@@ -918,7 +873,7 @@ int convert_timedelta_to_timedeltastruct(pandas_timedelta_metadata *meta,
918873    /* Initialize the output to all zeros */ 
919874    memset (out , 0 , sizeof (pandas_timedeltastruct ));
920875
921-     switch  (meta -> base ) {
876+     switch  (base ) {
922877        case  PANDAS_FR_ns :
923878
924879        // put frac in seconds 
0 commit comments