@@ -1235,11 +1235,11 @@ static char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc,
1235
1235
}
1236
1236
1237
1237
int is_datetimelike = 0 ;
1238
- npy_int64 i8date ;
1238
+ int64_t i8date ;
1239
1239
NPY_DATETIMEUNIT dateUnit = NPY_FR_ns ;
1240
1240
if (PyTypeNum_ISDATETIME (type_num )) {
1241
1241
is_datetimelike = 1 ;
1242
- i8date = * (npy_int64 * )dataptr ;
1242
+ i8date = * (int64_t * )dataptr ;
1243
1243
dateUnit = get_datetime_metadata_from_dtype (dtype ).base ;
1244
1244
} else if (PyDate_Check (item ) || PyDelta_Check (item )) {
1245
1245
is_datetimelike = 1 ;
@@ -1249,7 +1249,11 @@ static char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc,
1249
1249
i8date = get_long_attr (item , "_value" );
1250
1250
} else {
1251
1251
if (PyDelta_Check (item )) {
1252
- i8date = total_seconds (item ) * 1000000000LL ; // nanoseconds per second
1252
+ // TODO(anyone): cast below loses precision if total_seconds return
1253
+ // value exceeds number of bits that significand can hold
1254
+ // also liable to overflow
1255
+ i8date = (int64_t )(total_seconds (item ) *
1256
+ 1000000000LL ); // nanoseconds per second
1253
1257
} else {
1254
1258
// datetime.* objects don't follow above rules
1255
1259
i8date = PyDateTimeToEpoch (item , NPY_FR_ns );
@@ -1290,7 +1294,7 @@ static char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc,
1290
1294
ret = 0 ;
1291
1295
break ;
1292
1296
}
1293
- snprintf (cLabel , size_of_cLabel , "%" NPY_DATETIME_FMT , i8date );
1297
+ snprintf (cLabel , size_of_cLabel , "%" PRId64 , i8date );
1294
1298
len = strlen (cLabel );
1295
1299
}
1296
1300
}
@@ -1494,10 +1498,14 @@ static void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
1494
1498
}
1495
1499
return ;
1496
1500
} else if (PyDelta_Check (obj )) {
1497
- npy_int64 value =
1498
- PyObject_HasAttrString (obj , "_value" ) ? get_long_attr (obj , "_value" )
1499
- : // pd.Timedelta object or pd.NaT
1500
- total_seconds (obj ) * 1000000000LL ; // nanoseconds per sec
1501
+ // pd.Timedelta object or pd.NaT should evaluate true here
1502
+ // fallback to nanoseconds per sec for other objects
1503
+ // TODO(anyone): cast below loses precision if total_seconds return
1504
+ // value exceeds number of bits that significand can hold
1505
+ // also liable to overflow
1506
+ int64_t value = PyObject_HasAttrString (obj , "_value" )
1507
+ ? get_long_attr (obj , "_value" )
1508
+ : (int64_t )(total_seconds (obj ) * 1000000000LL );
1501
1509
1502
1510
if (value == get_nat ()) {
1503
1511
tc -> type = JT_NULL ;
0 commit comments