@@ -21,6 +21,7 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
21
21
22
22
#include <numpy/arrayobject.h>
23
23
#include <numpy/arrayscalars.h>
24
+ #include <numpy/ndarraytypes.h>
24
25
#include "np_datetime.h"
25
26
26
27
#if PY_MAJOR_VERSION >= 3
@@ -511,21 +512,21 @@ int convert_pydatetime_to_datetimestruct(PyObject *obj,
511
512
return -1 ;
512
513
}
513
514
514
- npy_datetime pandas_datetimestruct_to_datetime (PANDAS_DATETIMEUNIT fr ,
515
+ npy_datetime pandas_datetimestruct_to_datetime (NPY_DATETIMEUNIT fr ,
515
516
pandas_datetimestruct * d ) {
516
- npy_datetime result = PANDAS_DATETIME_NAT ;
517
+ npy_datetime result = NPY_DATETIME_NAT ;
517
518
518
519
convert_datetimestruct_to_datetime (fr , d , & result );
519
520
return result ;
520
521
}
521
522
522
- void pandas_datetime_to_datetimestruct (npy_datetime val , PANDAS_DATETIMEUNIT fr ,
523
+ void pandas_datetime_to_datetimestruct (npy_datetime val , NPY_DATETIMEUNIT fr ,
523
524
pandas_datetimestruct * result ) {
524
525
convert_datetime_to_datetimestruct (fr , val , result );
525
526
}
526
527
527
528
void pandas_timedelta_to_timedeltastruct (npy_timedelta val ,
528
- PANDAS_DATETIMEUNIT fr ,
529
+ NPY_DATETIMEUNIT fr ,
529
530
pandas_timedeltastruct * result ) {
530
531
convert_timedelta_to_timedeltastruct (fr , val , result );
531
532
}
@@ -537,71 +538,71 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta val,
537
538
*
538
539
* Returns 0 on success, -1 on failure.
539
540
*/
540
- int convert_datetimestruct_to_datetime (PANDAS_DATETIMEUNIT base ,
541
+ int convert_datetimestruct_to_datetime (NPY_DATETIMEUNIT base ,
541
542
const pandas_datetimestruct * dts ,
542
543
npy_datetime * out ) {
543
544
npy_datetime ret ;
544
545
545
- if (base == PANDAS_FR_Y ) {
546
+ if (base == NPY_FR_Y ) {
546
547
/* Truncate to the year */
547
548
ret = dts -> year - 1970 ;
548
- } else if (base == PANDAS_FR_M ) {
549
+ } else if (base == NPY_FR_M ) {
549
550
/* Truncate to the month */
550
551
ret = 12 * (dts -> year - 1970 ) + (dts -> month - 1 );
551
552
} else {
552
553
/* Otherwise calculate the number of days to start */
553
554
npy_int64 days = get_datetimestruct_days (dts );
554
555
555
556
switch (base ) {
556
- case PANDAS_FR_W :
557
+ case NPY_FR_W :
557
558
/* Truncate to weeks */
558
559
if (days >= 0 ) {
559
560
ret = days / 7 ;
560
561
} else {
561
562
ret = (days - 6 ) / 7 ;
562
563
}
563
564
break ;
564
- case PANDAS_FR_D :
565
+ case NPY_FR_D :
565
566
ret = days ;
566
567
break ;
567
- case PANDAS_FR_h :
568
+ case NPY_FR_h :
568
569
ret = days * 24 + dts -> hour ;
569
570
break ;
570
- case PANDAS_FR_m :
571
+ case NPY_FR_m :
571
572
ret = (days * 24 + dts -> hour ) * 60 + dts -> min ;
572
573
break ;
573
- case PANDAS_FR_s :
574
+ case NPY_FR_s :
574
575
ret = ((days * 24 + dts -> hour ) * 60 + dts -> min ) * 60 + dts -> sec ;
575
576
break ;
576
- case PANDAS_FR_ms :
577
+ case NPY_FR_ms :
577
578
ret = (((days * 24 + dts -> hour ) * 60 + dts -> min ) * 60 +
578
579
dts -> sec ) *
579
580
1000 +
580
581
dts -> us / 1000 ;
581
582
break ;
582
- case PANDAS_FR_us :
583
+ case NPY_FR_us :
583
584
ret = (((days * 24 + dts -> hour ) * 60 + dts -> min ) * 60 +
584
585
dts -> sec ) *
585
586
1000000 +
586
587
dts -> us ;
587
588
break ;
588
- case PANDAS_FR_ns :
589
+ case NPY_FR_ns :
589
590
ret = ((((days * 24 + dts -> hour ) * 60 + dts -> min ) * 60 +
590
591
dts -> sec ) *
591
592
1000000 +
592
593
dts -> us ) *
593
594
1000 +
594
595
dts -> ps / 1000 ;
595
596
break ;
596
- case PANDAS_FR_ps :
597
+ case NPY_FR_ps :
597
598
ret = ((((days * 24 + dts -> hour ) * 60 + dts -> min ) * 60 +
598
599
dts -> sec ) *
599
600
1000000 +
600
601
dts -> us ) *
601
602
1000000 +
602
603
dts -> ps ;
603
604
break ;
604
- case PANDAS_FR_fs :
605
+ case NPY_FR_fs :
605
606
/* only 2.6 hours */
606
607
ret = (((((days * 24 + dts -> hour ) * 60 + dts -> min ) * 60 +
607
608
dts -> sec ) *
@@ -612,7 +613,7 @@ int convert_datetimestruct_to_datetime(PANDAS_DATETIMEUNIT base,
612
613
1000 +
613
614
dts -> as / 1000 ;
614
615
break ;
615
- case PANDAS_FR_as :
616
+ case NPY_FR_as :
616
617
/* only 9.2 secs */
617
618
ret = (((((days * 24 + dts -> hour ) * 60 + dts -> min ) * 60 +
618
619
dts -> sec ) *
@@ -640,7 +641,7 @@ int convert_datetimestruct_to_datetime(PANDAS_DATETIMEUNIT base,
640
641
/*
641
642
* Converts a datetime based on the given metadata into a datetimestruct
642
643
*/
643
- int convert_datetime_to_datetimestruct (PANDAS_DATETIMEUNIT base ,
644
+ int convert_datetime_to_datetimestruct (NPY_DATETIMEUNIT base ,
644
645
npy_datetime dt ,
645
646
pandas_datetimestruct * out ) {
646
647
npy_int64 perday ;
@@ -656,11 +657,11 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
656
657
* for negative values.
657
658
*/
658
659
switch (base ) {
659
- case PANDAS_FR_Y :
660
+ case NPY_FR_Y :
660
661
out -> year = 1970 + dt ;
661
662
break ;
662
663
663
- case PANDAS_FR_M :
664
+ case NPY_FR_M :
664
665
if (dt >= 0 ) {
665
666
out -> year = 1970 + dt / 12 ;
666
667
out -> month = dt % 12 + 1 ;
@@ -670,16 +671,16 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
670
671
}
671
672
break ;
672
673
673
- case PANDAS_FR_W :
674
+ case NPY_FR_W :
674
675
/* A week is 7 days */
675
676
set_datetimestruct_days (dt * 7 , out );
676
677
break ;
677
678
678
- case PANDAS_FR_D :
679
+ case NPY_FR_D :
679
680
set_datetimestruct_days (dt , out );
680
681
break ;
681
682
682
- case PANDAS_FR_h :
683
+ case NPY_FR_h :
683
684
perday = 24LL ;
684
685
685
686
if (dt >= 0 ) {
@@ -693,7 +694,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
693
694
out -> hour = dt ;
694
695
break ;
695
696
696
- case PANDAS_FR_m :
697
+ case NPY_FR_m :
697
698
perday = 24LL * 60 ;
698
699
699
700
if (dt >= 0 ) {
@@ -708,7 +709,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
708
709
out -> min = dt % 60 ;
709
710
break ;
710
711
711
- case PANDAS_FR_s :
712
+ case NPY_FR_s :
712
713
perday = 24LL * 60 * 60 ;
713
714
714
715
if (dt >= 0 ) {
@@ -724,7 +725,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
724
725
out -> sec = dt % 60 ;
725
726
break ;
726
727
727
- case PANDAS_FR_ms :
728
+ case NPY_FR_ms :
728
729
perday = 24LL * 60 * 60 * 1000 ;
729
730
730
731
if (dt >= 0 ) {
@@ -741,7 +742,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
741
742
out -> us = (dt % 1000LL ) * 1000 ;
742
743
break ;
743
744
744
- case PANDAS_FR_us :
745
+ case NPY_FR_us :
745
746
perday = 24LL * 60LL * 60LL * 1000LL * 1000LL ;
746
747
747
748
if (dt >= 0 ) {
@@ -758,7 +759,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
758
759
out -> us = dt % 1000000LL ;
759
760
break ;
760
761
761
- case PANDAS_FR_ns :
762
+ case NPY_FR_ns :
762
763
perday = 24LL * 60LL * 60LL * 1000LL * 1000LL * 1000LL ;
763
764
764
765
if (dt >= 0 ) {
@@ -776,7 +777,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
776
777
out -> ps = (dt % 1000LL ) * 1000 ;
777
778
break ;
778
779
779
- case PANDAS_FR_ps :
780
+ case NPY_FR_ps :
780
781
perday = 24LL * 60 * 60 * 1000 * 1000 * 1000 * 1000 ;
781
782
782
783
if (dt >= 0 ) {
@@ -794,7 +795,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
794
795
out -> ps = dt % 1000000LL ;
795
796
break ;
796
797
797
- case PANDAS_FR_fs :
798
+ case NPY_FR_fs :
798
799
/* entire range is only +- 2.6 hours */
799
800
if (dt >= 0 ) {
800
801
out -> hour = dt / (60 * 60 * 1000000000000000LL );
@@ -821,7 +822,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
821
822
}
822
823
break ;
823
824
824
- case PANDAS_FR_as :
825
+ case NPY_FR_as :
825
826
/* entire range is only +- 9.2 seconds */
826
827
if (dt >= 0 ) {
827
828
out -> sec = (dt / 1000000000000000000LL ) % 60 ;
@@ -861,7 +862,7 @@ int convert_datetime_to_datetimestruct(PANDAS_DATETIMEUNIT base,
861
862
*
862
863
* Returns 0 on success, -1 on failure.
863
864
*/
864
- int convert_timedelta_to_timedeltastruct (PANDAS_DATETIMEUNIT base ,
865
+ int convert_timedelta_to_timedeltastruct (NPY_DATETIMEUNIT base ,
865
866
npy_timedelta td ,
866
867
pandas_timedeltastruct * out ) {
867
868
npy_int64 frac ;
@@ -874,7 +875,7 @@ int convert_timedelta_to_timedeltastruct(PANDAS_DATETIMEUNIT base,
874
875
memset (out , 0 , sizeof (pandas_timedeltastruct ));
875
876
876
877
switch (base ) {
877
- case PANDAS_FR_ns :
878
+ case NPY_FR_ns :
878
879
879
880
// put frac in seconds
880
881
if (td < 0 && td % (1000LL * 1000LL * 1000LL ) != 0 )
0 commit comments