示例#1
0
文件: period.c 项目: takluyver/pandas
static long_t asfreq_QtoD(long_t fromDate, char relation, asfreq_info *af_info) {

    long_t y, m, absdate;

    if (relation == 'S') {
        QtoD_ym(fromDate, &y, &m, af_info);
        if ((absdate = absdate_from_ymd(y, m, 1)) == INT_ERR_CODE) return INT_ERR_CODE;
        return absdate;
    } else {
        QtoD_ym(fromDate+1, &y, &m, af_info);
        if ((absdate = absdate_from_ymd(y, m, 1)) == INT_ERR_CODE) return INT_ERR_CODE;
        return absdate - 1;
    }
}
示例#2
0
static int64_t asfreq_MtoD(int64_t fromDate, char relation, asfreq_info *af_info) {

    int64_t y, m, absdate;

    if (relation == 'S') {
        MtoD_ym(fromDate, &y, &m);
        if ((absdate = absdate_from_ymd(y, m, 1)) == INT_ERR_CODE) return INT_ERR_CODE;
        return absdate;
    } else {
        MtoD_ym(fromDate+1, &y, &m);
        if ((absdate = absdate_from_ymd(y, m, 1)) == INT_ERR_CODE) return INT_ERR_CODE;
        return absdate-1;
    }
}
示例#3
0
static npy_int64 asfreq_MtoD(npy_int64 ordinal, char relation, asfreq_info *af_info) {

    npy_int64 absdate;
    int y, m;

    if (relation == 'S') {
        MtoD_ym(ordinal, &y, &m);
        if ((absdate = absdate_from_ymd(y, m, 1)) == INT_ERR_CODE) return INT_ERR_CODE;
        return absdate - ORD_OFFSET;
    } else {
        MtoD_ym(ordinal + 1, &y, &m);
        if ((absdate = absdate_from_ymd(y, m, 1)) == INT_ERR_CODE) return INT_ERR_CODE;
        return absdate - 1 - ORD_OFFSET;
    }
}
示例#4
0
文件: period.c 项目: Vistarino/pandas
static npy_int64 asfreq_AtoDT(npy_int64 year, char relation, asfreq_info *af_info) {
    npy_int64 absdate;
    int month = (af_info->from_a_year_end) % 12;

    // start from 1970
    year += BASE_YEAR;

    month += 1;

    if (af_info->from_a_year_end != 12) {
      year -= 1;
    }

    if (relation == 'E') {
      year += 1;
    }

    absdate = absdate_from_ymd(year, month, 1);

    if (absdate  == INT_ERR_CODE) {
        return INT_ERR_CODE;
    }

    if (relation == 'E') {
      absdate -= 1;
    }

    return convert_daytime(absdate - ORD_OFFSET, FR_DAY, af_info->targetFreq, relation != 'S');
}
示例#5
0
static npy_int64 asfreq_AtoD(npy_int64 ordinal, char relation, asfreq_info *af_info) {
    npy_int64 absdate, final_adj;
	int year;
    int month = (af_info->from_a_year_end) % 12;

	// start from 1970
	ordinal += BASE_YEAR;

    if (month == 0) { month = 1; }
    else { month += 1; }

    if (relation == 'S') {
        if (af_info->from_a_year_end == 12) {year = ordinal;}
        else {year = ordinal - 1;}
        final_adj = 0;
    } else {
        if (af_info->from_a_year_end == 12) {year = ordinal+1;}
        else {year = ordinal;}
        final_adj = -1;
    }
    absdate = absdate_from_ymd(year, month, 1);
    if (absdate  == INT_ERR_CODE) {
	  return INT_ERR_CODE;
	}
    return absdate + final_adj - ORD_OFFSET;
}
示例#6
0
static npy_int64 asfreq_QtoD(npy_int64 ordinal, char relation, asfreq_info *af_info) {

    npy_int64 absdate;
    int y, m;

    if (relation == 'S') {
        QtoD_ym(ordinal, &y, &m, af_info);
		// printf("ordinal: %d, year: %d, month: %d\n", (int) ordinal, y, m);
        if ((absdate = absdate_from_ymd(y, m, 1)) == INT_ERR_CODE) return INT_ERR_CODE;
        return absdate - ORD_OFFSET;
    } else {
        QtoD_ym(ordinal+1, &y, &m, af_info);
		/* printf("ordinal: %d, year: %d, month: %d\n", (int) ordinal, y, m); */
        if ((absdate = absdate_from_ymd(y, m, 1)) == INT_ERR_CODE) return INT_ERR_CODE;
        return absdate - 1 - ORD_OFFSET;
    }
}
示例#7
0
文件: period.c 项目: Vistarino/pandas
static npy_int64 asfreq_MtoDT(npy_int64 ordinal, char relation, asfreq_info* af_info) {
    npy_int64 absdate;
    int y, m;

    if (relation == 'E') {
      ordinal += 1;
    }
    MtoD_ym(ordinal, &y, &m);
    if ((absdate = absdate_from_ymd(y, m, 1)) == INT_ERR_CODE) return INT_ERR_CODE;
    ordinal = absdate - ORD_OFFSET;

    if (relation == 'E') {
      ordinal -= 1;
    }

    return convert_daytime(ordinal, FR_DAY, af_info->targetFreq, relation != 'S');
}
示例#8
0
文件: period.c 项目: takluyver/pandas
static long_t asfreq_AtoD(long_t fromDate, char relation, asfreq_info *af_info) {
    long_t absdate, year, final_adj;
    int month = (af_info->from_a_year_end) % 12;

    if (month == 0) { month = 1; }
    else { month += 1; }

    if (relation == 'S') {
        if (af_info->from_a_year_end == 12) {year = fromDate;}
        else {year = fromDate - 1;}
        final_adj = 0;
    } else {
        if (af_info->from_a_year_end == 12) {year = fromDate+1;}
        else {year = fromDate;}
        final_adj = -1;
    }
    absdate = absdate_from_ymd(year, month, 1);
    if (absdate  == INT_ERR_CODE) return INT_ERR_CODE;
    return absdate + final_adj;
}
示例#9
0
文件: period.c 项目: Vistarino/pandas
/* generate an ordinal in period space */
npy_int64 get_period_ordinal(int year, int month, int day,
        int hour, int minute, int second, int microseconds, int picoseconds,
        int freq)
{
    npy_int64 absdays, delta, seconds;
    npy_int64 weeks, days;
    npy_int64 ordinal, day_adj;
    int freq_group, fmonth, mdiff;
    freq_group = get_freq_group(freq);

    if (freq == FR_SEC || freq == FR_MS || freq == FR_US || freq == FR_NS) {

        absdays = absdate_from_ymd(year, month, day);
        delta = (absdays - ORD_OFFSET);
        seconds = (npy_int64)(delta * 86400 + hour * 3600 + minute * 60 + second);

        switch(freq) {
          case FR_MS:
            return seconds * 1000 + microseconds / 1000;

          case FR_US:
            return seconds * 1000000 + microseconds;

          case FR_NS:
            return seconds * 1000000000 + microseconds * 1000 + picoseconds / 1000;
        }

        return seconds;
    }

    if (freq == FR_MIN) {
        absdays = absdate_from_ymd(year, month, day);
        delta = (absdays - ORD_OFFSET);
        return (npy_int64)(delta*1440 + hour*60 + minute);
    }

    if (freq == FR_HR) {
        if ((absdays = absdate_from_ymd(year, month, day)) == INT_ERR_CODE)
        {
            goto onError;
        }
        delta = (absdays - ORD_OFFSET);
        return (npy_int64)(delta*24 + hour);
    }

    if (freq == FR_DAY)
    {
        return (npy_int64) (absdate_from_ymd(year, month, day) - ORD_OFFSET);
    }

    if (freq == FR_UND)
    {
        return (npy_int64) (absdate_from_ymd(year, month, day) - ORD_OFFSET);
    }

    if (freq == FR_BUS)
    {
        if((days = absdate_from_ymd(year, month, day)) == INT_ERR_CODE)
        {
            goto onError;
        }
        weeks = days / 7;
        return (npy_int64)(days - weeks * 2) - BDAY_OFFSET;
    }

    if (freq_group == FR_WK)
    {
        if((ordinal = (npy_int64)absdate_from_ymd(year, month, day)) == INT_ERR_CODE)
        {
            goto onError;
        }
        day_adj = freq - FR_WK;
        return (ordinal - (1 + day_adj)) / 7 + 1 - WEEK_OFFSET;
    }

    if (freq == FR_MTH)
    {
        return (year - BASE_YEAR) * 12 + month - 1;
    }

    if (freq_group == FR_QTR)
    {
        fmonth = freq - FR_QTR;
        if (fmonth == 0) fmonth = 12;

        mdiff = month - fmonth;
        if (mdiff < 0) mdiff += 12;
        if (month >= fmonth) mdiff += 12;

        return (year - BASE_YEAR) * 4 + (mdiff - 1) / 3;
    }

    if (freq_group == FR_ANN)
    {
        fmonth = freq - FR_ANN;
        if (fmonth == 0) fmonth = 12;
        if (month <= fmonth) {
            return year - BASE_YEAR;
        }
        else {
            return year - BASE_YEAR + 1;
        }
    }

    Py_Error(PyExc_RuntimeError, "Unable to generate frequency ordinal");

onError:
    return INT_ERR_CODE;
}
示例#10
0
文件: period.c 项目: takluyver/pandas
/* generate an ordinal in period space */
long_t get_period_ordinal(int year, int month, int day,
                      int hour, int minute, int second,
                      int freq)
{
    int freq_group = get_freq_group(freq);
    int quarter=((month-1)/3)+1;

    if (freq == FR_SEC) {
        long_t absdays, delta;
        absdays = absdate_from_ymd(year, month, day);
        delta = (absdays - HIGHFREQ_ORIG);
        return (long_t)(delta*86400 + hour*3600 + minute*60 + second + 1);
    }

    if (freq == FR_MIN) {
        long_t absdays, delta;
        absdays = absdate_from_ymd(year, month, day);
        delta = (absdays - HIGHFREQ_ORIG);
        return (long_t)(delta*1440 + hour*60 + minute + 1);
    }

    if (freq == FR_HR) {
        long_t absdays, delta;
        if ((absdays = absdate_from_ymd(year, month, day)) == INT_ERR_CODE)
        {
            goto onError;
        }
        delta = (absdays - HIGHFREQ_ORIG);
        return (long_t)(delta*24 + hour + 1);
    }

    if (freq == FR_DAY)
    {
        return (long_t)absdate_from_ymd(year, month, day);
    }

    if (freq == FR_UND)
    {
        return (long_t)absdate_from_ymd(year, month, day);
    }

    if (freq == FR_BUS)
    {
        long_t weeks, days;
        if((days = absdate_from_ymd(year, month, day)) == INT_ERR_CODE)
        {
            goto onError;
        }
        weeks = days/7;
        return (long_t)(days - weeks*2);
    }

    if (freq_group == FR_WK)
    {
        long_t adj_ordinal, ordinal, day_adj;
        if((ordinal = (long_t)absdate_from_ymd(year, month, day)) == INT_ERR_CODE)
        {
            goto onError;
        }
        day_adj = (7 - (freq - FR_WK)) % 7;
        adj_ordinal = ordinal + ((7 - day_adj) - ordinal % 7) % 7;
        return adj_ordinal/7;
    }

    if (freq == FR_MTH)
    {
        return (year-1)*12 + month;
    }

    if (freq_group == FR_QTR)
    {
        return (year-1)*4 + quarter;
    }

    if (freq_group == FR_ANN)
    {
        return year;
    }

    Py_Error(PyExc_RuntimeError, "Unable to generate frequency ordinal");

onError:
    return INT_ERR_CODE;
}
示例#11
0
/* generate an ordinal in period space */
int64_t get_period_ordinal(int year, int month, int day,
                      int hour, int minute, int second,
                      int freq)
{
	  int64_t absdays, delta;
    int64_t weeks, days;
    int64_t adj_ordinal, ordinal, day_adj;
    int freq_group, fmonth, mdiff, quarter;
    freq_group = get_freq_group(freq);

    if (freq == FR_SEC) {
        absdays = absdate_from_ymd(year, month, day);
        delta = (absdays - HIGHFREQ_ORIG);
        return (int64_t)(delta*86400 + hour*3600 + minute*60 + second + 1);
    }

    if (freq == FR_MIN) {
        absdays = absdate_from_ymd(year, month, day);
        delta = (absdays - HIGHFREQ_ORIG);
        return (int64_t)(delta*1440 + hour*60 + minute + 1);
    }

    if (freq == FR_HR) {
        if ((absdays = absdate_from_ymd(year, month, day)) == INT_ERR_CODE)
        {
            goto onError;
        }
        delta = (absdays - HIGHFREQ_ORIG);
        return (int64_t)(delta*24 + hour + 1);
    }

    if (freq == FR_DAY)
    {
        return (int64_t)absdate_from_ymd(year, month, day);
    }

    if (freq == FR_UND)
    {
        return (int64_t)absdate_from_ymd(year, month, day);
    }

    if (freq == FR_BUS)
    {
        if((days = absdate_from_ymd(year, month, day)) == INT_ERR_CODE)
        {
            goto onError;
        }
        weeks = days/7;
        return (int64_t)(days - weeks*2);
    }

    if (freq_group == FR_WK)
    {
        if((ordinal = (int64_t)absdate_from_ymd(year, month, day)) == INT_ERR_CODE)
        {
            goto onError;
        }
        day_adj = (7 - (freq - FR_WK)) % 7;
        adj_ordinal = ordinal + ((7 - day_adj) - ordinal % 7) % 7;
        return adj_ordinal/7;
    }

    if (freq == FR_MTH)
    {
        return (year-1)*12 + month;
    }

    if (freq_group == FR_QTR)
    {
      fmonth = freq - FR_QTR;
      if (fmonth == 0) fmonth = 12;

      mdiff = month - fmonth;
      if (mdiff < 0) mdiff += 12;
      if (month >= fmonth) mdiff += 12;

      return 1 + (year - 1) * 4 + (mdiff - 1) / 3;
    }

    if (freq_group == FR_ANN)
    {
      fmonth = freq - FR_ANN;
      if (fmonth == 0) fmonth = 12;
      if (month <= fmonth) {
        return year;
      }
      else {
        return year + 1;
      }
    }

    Py_Error(PyExc_RuntimeError, "Unable to generate frequency ordinal");

onError:
    return INT_ERR_CODE;
}