Skip to content

Commit b3c0eb0

Browse files
committed
BUG: more intraday unit fixes
1 parent 3e2a7f4 commit b3c0eb0

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

pandas/src/period.c

+18-24
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,13 @@ static npy_int64 asfreq_DtoB_forConvert(npy_int64 ordinal, char relation, asfreq
367367
// needed for getDateInfo function
368368
static npy_int64 asfreq_DtoD(npy_int64 ordinal, char relation, asfreq_info *af_info) { return ordinal; }
369369

370-
static npy_int64 asfreq_DtoHIGHFREQ(npy_int64 ordinal, char relation, npy_int64 periodsPerDay) {
370+
static npy_int64 asfreq_DtoHIGHFREQ(npy_int64 ordinal, char relation, npy_int64 per_day) {
371371
if (ordinal >= HIGHFREQ_ORIG) {
372372
if (relation == 'S') {
373-
return (ordinal - HIGHFREQ_ORIG)*(periodsPerDay) + 1;
373+
return (ordinal - HIGHFREQ_ORIG) * per_day;
374374
}
375375
else {
376-
return (ordinal - HIGHFREQ_ORIG + 1)*(periodsPerDay);
376+
return (ordinal - HIGHFREQ_ORIG + 1) * per_day - 1;
377377
}
378378
} else { return INT_ERR_CODE; }
379379
}
@@ -388,7 +388,7 @@ static npy_int64 asfreq_DtoS(npy_int64 ordinal, char relation, asfreq_info *af_i
388388
//************ FROM SECONDLY ***************
389389

390390
static npy_int64 asfreq_StoD(npy_int64 ordinal, char relation, asfreq_info *af_info)
391-
{ return (ordinal - 1)/(60*60*24) + HIGHFREQ_ORIG; }
391+
{ return (ordinal)/(60*60*24) + HIGHFREQ_ORIG; }
392392

393393
static npy_int64 asfreq_StoA(npy_int64 ordinal, char relation, asfreq_info *af_info)
394394
{ return asfreq_DtoA(asfreq_StoD(ordinal, relation, &NULL_AF_INFO), relation, af_info); }
@@ -410,7 +410,7 @@ static npy_int64 asfreq_StoH(npy_int64 ordinal, char relation, asfreq_info *af_i
410410
//************ FROM MINUTELY ***************
411411

412412
static npy_int64 asfreq_TtoD(npy_int64 ordinal, char relation, asfreq_info *af_info)
413-
{ return (ordinal - 1)/(60*24) + HIGHFREQ_ORIG; }
413+
{ return (ordinal)/(60*24) + HIGHFREQ_ORIG; }
414414

415415
static npy_int64 asfreq_TtoA(npy_int64 ordinal, char relation, asfreq_info *af_info)
416416
{ return asfreq_DtoA(asfreq_TtoD(ordinal, relation, &NULL_AF_INFO), relation, af_info); }
@@ -435,7 +435,7 @@ static npy_int64 asfreq_TtoS(npy_int64 ordinal, char relation, asfreq_info *af_i
435435
//************ FROM HOURLY ***************
436436

437437
static npy_int64 asfreq_HtoD(npy_int64 ordinal, char relation, asfreq_info *af_info)
438-
{ return (ordinal - 1)/24 + HIGHFREQ_ORIG; }
438+
{ return ordinal / 24 + HIGHFREQ_ORIG; }
439439
static npy_int64 asfreq_HtoA(npy_int64 ordinal, char relation, asfreq_info *af_info)
440440
{ return asfreq_DtoA(asfreq_HtoD(ordinal, relation, &NULL_AF_INFO), relation, af_info); }
441441
static npy_int64 asfreq_HtoQ(npy_int64 ordinal, char relation, asfreq_info *af_info)
@@ -907,28 +907,27 @@ freq_conv_func get_asfreq_func(int fromFreq, int toFreq, int forConvert)
907907
}
908908
}
909909

910-
double getAbsTime(int freq, npy_int64 dailyDate, npy_int64 originalDate) {
910+
double get_abs_time(int freq, npy_int64 daily_ord, npy_int64 ordinal) {
911911

912-
npy_int64 startOfDay, periodsPerDay;
912+
npy_int64 start_ord, per_day;
913913

914914
switch(freq)
915915
{
916916
case FR_HR:
917-
periodsPerDay = 24;
917+
per_day = 24;
918918
break;
919919
case FR_MIN:
920-
periodsPerDay = 24*60;
920+
per_day = 24*60;
921921
break;
922922
case FR_SEC:
923-
periodsPerDay = 24*60*60;
923+
per_day = 24*60*60;
924924
break;
925925
default:
926926
return 0; // 24*60*60 - 1;
927927
}
928928

929-
startOfDay = asfreq_DtoHIGHFREQ(dailyDate- ORD_OFFSET, 'S',
930-
periodsPerDay);
931-
return (24*60*60)*((double)(originalDate - startOfDay))/((double)periodsPerDay);
929+
start_ord = asfreq_DtoHIGHFREQ(daily_ord, 'S', per_day);
930+
return (24*60*60)*((double) (ordinal - start_ord)) / ((double) per_day);
932931
}
933932

934933
/* Sets the time part of the DateTime object. */
@@ -971,15 +970,10 @@ int dInfoCalc_SetFromAbsDateTime(struct date_info *dinfo,
971970
abstime);
972971

973972
/* Calculate the date */
974-
if (dInfoCalc_SetFromAbsDate(dinfo,
975-
absdate,
976-
calendar))
977-
goto onError;
973+
if (dInfoCalc_SetFromAbsDate(dinfo, absdate, calendar)) goto onError;
978974

979975
/* Calculate the time */
980-
if (dInfoCalc_SetFromAbsTime(dinfo,
981-
abstime))
982-
goto onError;
976+
if (dInfoCalc_SetFromAbsTime(dinfo, abstime)) goto onError;
983977

984978
return 0;
985979
onError:
@@ -1193,9 +1187,9 @@ char *skts_strftime(npy_int64 ordinal, int freq, PyObject *args)
11931187
get_asfreq_info(freq, FR_DAY, &af_info);
11941188

11951189
daily_ord = toDaily(ordinal, 'E', &af_info);
1196-
abstime = getAbsTime(freq, daily_ord + ORD_OFFSET, ordinal);
1190+
abstime = get_abs_time(freq, daily_ord, ordinal);
11971191

1198-
// printf("daily_ord: %d\n", (int) daily_ord);
1192+
printf("daily_ord: %d, abstime: %f \n", (int) daily_ord, abstime);
11991193

12001194
if(dInfoCalc_SetFromAbsDateTime(&tempDate, daily_ord + ORD_OFFSET, abstime,
12011195
GREGORIAN_CALENDAR)) return NULL;
@@ -1395,7 +1389,7 @@ int get_date_info(npy_int64 ordinal, int freq, struct date_info *dinfo)
13951389
{
13961390
npy_int64 absdate = get_python_ordinal(ordinal, freq);
13971391
/* printf("freq: %d, absdate: %d\n", freq, (int) absdate); */
1398-
double abstime = getAbsTime(freq, absdate, ordinal);
1392+
double abstime = get_abs_time(freq, absdate - ORD_OFFSET, ordinal);
13991393

14001394
if(dInfoCalc_SetFromAbsDateTime(dinfo, absdate,
14011395
abstime, GREGORIAN_CALENDAR))

setup.py

+18-9
Original file line numberDiff line numberDiff line change
@@ -354,15 +354,24 @@ def srcpath(name=None, suffix='.pyx', subdir='src'):
354354
)
355355

356356
tseries_ext = Extension('pandas._tseries',
357-
depends=tseries_depends + ['pandas/src/numpy_helper.h'],
358-
sources=[srcpath('tseries', suffix=suffix),
359-
'pandas/src/period.c',
360-
'pandas/src/np_datetime.c',
361-
'pandas/src/np_datetime_strings.c'],
362-
include_dirs=[np.get_include()],
363-
# pyrex_gdb=True,
364-
# extra_compile_args=['-Wconversion']
365-
)
357+
depends=tseries_depends + ['pandas/src/numpy_helper.h'],
358+
sources=[srcpath('tseries', suffix=suffix),
359+
'pandas/src/period.c',
360+
'pandas/src/np_datetime.c',
361+
'pandas/src/np_datetime_strings.c'],
362+
include_dirs=[np.get_include()],
363+
# pyrex_gdb=True,
364+
# extra_compile_args=['-Wconversion']
365+
)
366+
367+
# tseries_ext = Extension('pandas._tseries',
368+
# depends=tseries_depends + ['pandas/src/numpy_helper.h'],
369+
# sources=[srcpath('datetime', suffix=suffix)],
370+
# include_dirs=[np.get_include()],
371+
# # pyrex_gdb=True,
372+
# # extra_compile_args=['-Wconversion']
373+
# )
374+
366375

367376
sparse_ext = Extension('pandas._sparse',
368377
sources=[srcpath('sparse', suffix=suffix)],

0 commit comments

Comments
 (0)