@@ -564,18 +564,15 @@ void pandas_datetime_to_datetimestruct(npy_datetime val, PANDAS_DATETIMEUNIT fr,
564
564
565
565
void pandas_timedelta_to_timedeltastruct (npy_timedelta val ,
566
566
PANDAS_DATETIMEUNIT fr ,
567
- pandas_timedeltastruct * result ) {
567
+ pandas_timedeltastruct * result ) {
568
568
pandas_datetime_metadata meta ;
569
569
570
570
meta .base = fr ;
571
- meta .num - 1 ;
571
+ meta .num = 1 ;
572
572
573
573
convert_timedelta_to_timedeltastruct (& meta , val , result );
574
574
}
575
575
576
- PANDAS_DATETIMEUNIT get_datetime64_unit (PyObject * obj ) {
577
- return (PANDAS_DATETIMEUNIT )((PyDatetimeScalarObject * )obj )-> obmeta .base ;
578
- }
579
576
580
577
/*
581
578
* Converts a datetime from a datetimestruct to a datetime based
@@ -1001,7 +998,6 @@ int convert_datetime_to_datetimestruct(pandas_datetime_metadata *meta,
1001
998
int convert_timedelta_to_timedeltastruct (pandas_timedelta_metadata * meta ,
1002
999
npy_timedelta td ,
1003
1000
pandas_timedeltastruct * out ) {
1004
- npy_int64 perday ;
1005
1001
npy_int64 frac ;
1006
1002
npy_int64 sfrac ;
1007
1003
npy_int64 ifrac ;
@@ -1016,11 +1012,11 @@ int convert_timedelta_to_timedeltastruct(pandas_timedelta_metadata *meta,
1016
1012
1017
1013
// put frac in seconds
1018
1014
if (td < 0 && td % (1000LL * 1000LL * 1000LL ) != 0 )
1019
- frac = td / (1000LL * 1000LL * 1000LL ) - 1 ;
1015
+ frac = td / (1000LL * 1000LL * 1000LL ) - 1 ;
1020
1016
else
1021
1017
frac = td / (1000LL * 1000LL * 1000LL );
1022
1018
1023
- if (frac < 0 ) {
1019
+ if (frac < 0 ) {
1024
1020
sign = -1 ;
1025
1021
1026
1022
// even fraction
@@ -1030,66 +1026,66 @@ int convert_timedelta_to_timedeltastruct(pandas_timedelta_metadata *meta,
1030
1026
} else {
1031
1027
frac = - frac ;
1032
1028
}
1033
- } else {
1029
+ } else {
1034
1030
sign = 1 ;
1035
1031
out -> days = 0 ;
1036
- }
1032
+ }
1037
1033
1038
- if (frac >= 86400 ) {
1034
+ if (frac >= 86400 ) {
1039
1035
out -> days += frac / 86400LL ;
1040
1036
frac -= out -> days * 86400LL ;
1041
- }
1037
+ }
1042
1038
1043
- if (frac >= 3600 ) {
1039
+ if (frac >= 3600 ) {
1044
1040
out -> hrs = frac / 3600LL ;
1045
1041
frac -= out -> hrs * 3600LL ;
1046
- } else {
1042
+ } else {
1047
1043
out -> hrs = 0 ;
1048
- }
1044
+ }
1049
1045
1050
- if (frac >= 60 ) {
1046
+ if (frac >= 60 ) {
1051
1047
out -> min = frac / 60LL ;
1052
1048
frac -= out -> min * 60LL ;
1053
- } else {
1049
+ } else {
1054
1050
out -> min = 0 ;
1055
- }
1051
+ }
1056
1052
1057
- if (frac >= 0 ) {
1053
+ if (frac >= 0 ) {
1058
1054
out -> sec = frac ;
1059
1055
frac -= out -> sec ;
1060
- } else {
1056
+ } else {
1061
1057
out -> sec = 0 ;
1062
- }
1058
+ }
1063
1059
1064
- sfrac = (out -> hrs * 3600LL + out -> min * 60LL
1065
- + out -> sec ) * (1000LL * 1000LL * 1000LL );
1060
+ sfrac = (out -> hrs * 3600LL + out -> min * 60LL
1061
+ + out -> sec ) * (1000LL * 1000LL * 1000LL );
1066
1062
1067
- if (sign < 0 )
1063
+ if (sign < 0 )
1068
1064
out -> days = - out -> days ;
1069
1065
1070
- ifrac = td - (out -> days * DAY_NS + sfrac );
1066
+ ifrac = td - (out -> days * DAY_NS + sfrac );
1071
1067
1072
- if (ifrac != 0 ) {
1068
+ if (ifrac != 0 ) {
1073
1069
out -> ms = ifrac / (1000LL * 1000LL );
1074
1070
ifrac -= out -> ms * 1000LL * 1000LL ;
1075
1071
out -> us = ifrac / 1000LL ;
1076
1072
ifrac -= out -> us * 1000LL ;
1077
1073
out -> ns = ifrac ;
1078
- } else {
1074
+ } else {
1079
1075
out -> ms = 0 ;
1080
1076
out -> us = 0 ;
1081
1077
out -> ns = 0 ;
1082
- }
1078
+ }
1083
1079
1084
- out -> seconds = out -> hrs * 3600 + out -> min * 60 + out -> sec ;
1085
- out -> microseconds = out -> ms * 1000 + out -> us ;
1086
- out -> nanoseconds = out -> ns ;
1087
- break ;
1080
+ out -> seconds = out -> hrs * 3600 + out -> min * 60 + out -> sec ;
1081
+ out -> microseconds = out -> ms * 1000 + out -> us ;
1082
+ out -> nanoseconds = out -> ns ;
1083
+ break ;
1088
1084
1089
1085
default :
1090
1086
PyErr_SetString (PyExc_RuntimeError ,
1091
- "NumPy datetime metadata is corrupted with invalid "
1092
- "base unit" );
1087
+ "NumPy timedelta metadata is corrupted with "
1088
+ "invalid base unit" );
1093
1089
return -1 ;
1094
1090
}
1095
1091
0 commit comments