Skip to content

Commit 42be719

Browse files
committed
BUG: monthly periods prior to dec 1969 off by one year #1570
1 parent 0bdd555 commit 42be719

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

pandas/src/period.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ int dInfoCalc_SetFromAbsDate(register struct date_info *dinfo,
206206
} else {
207207
Py_Error(PyExc_ValueError, "unknown calendar");
208208
}
209+
209210
if (absdate > 0) year++;
210211

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

550551
//************ FROM MONTHLY ***************
551-
552552
static void MtoD_ym(npy_int64 ordinal, int *y, int *m) {
553-
*y = ordinal / 12 + BASE_YEAR;
553+
*y = floordiv(ordinal, 12) + BASE_YEAR;
554554
*m = mod_compat(ordinal, 12) + 1;
555555
}
556556

pandas/tseries/tests/test_period.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def test_quarterly_negative_ordinals(self):
4141
self.assertEquals(p.year, 1969)
4242
self.assertEquals(p.quarter, 3)
4343

44+
p = Period(ordinal=-2, freq='M')
45+
self.assertEquals(p.year, 1969)
46+
self.assertEquals(p.month, 11)
47+
4448
def test_period_cons_quarterly(self):
4549
# bugs in scikits.timeseries
4650
for month in MONTHS:

0 commit comments

Comments
 (0)