Skip to content

Commit

Permalink
BUG: monthly periods prior to dec 1969 off by one year #1570
Browse files Browse the repository at this point in the history
  • Loading branch information
changhiskhan committed Jul 6, 2012
1 parent 0bdd555 commit 42be719
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pandas/src/period.c
Expand Up @@ -206,6 +206,7 @@ int dInfoCalc_SetFromAbsDate(register struct date_info *dinfo,
} else {
Py_Error(PyExc_ValueError, "unknown calendar");
}

if (absdate > 0) year++;

/* Apply corrections to reach the correct year */
Expand Down Expand Up @@ -548,9 +549,8 @@ static npy_int64 asfreq_WtoS(npy_int64 ordinal, char relation, asfreq_info *af_i
{ return asfreq_DtoS(asfreq_WtoD(ordinal, relation, af_info), relation, &NULL_AF_INFO); }

//************ FROM MONTHLY ***************

static void MtoD_ym(npy_int64 ordinal, int *y, int *m) {
*y = ordinal / 12 + BASE_YEAR;
*y = floordiv(ordinal, 12) + BASE_YEAR;
*m = mod_compat(ordinal, 12) + 1;
}

Expand Down
4 changes: 4 additions & 0 deletions pandas/tseries/tests/test_period.py
Expand Up @@ -41,6 +41,10 @@ def test_quarterly_negative_ordinals(self):
self.assertEquals(p.year, 1969)
self.assertEquals(p.quarter, 3)

p = Period(ordinal=-2, freq='M')
self.assertEquals(p.year, 1969)
self.assertEquals(p.month, 11)

def test_period_cons_quarterly(self):
# bugs in scikits.timeseries
for month in MONTHS:
Expand Down

0 comments on commit 42be719

Please sign in to comment.