diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index 3ba0a034c9f80..bd9e61ba5d89b 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -1324,6 +1324,16 @@ def test_timeseries_repr_object_dtype(self): ts2 = ts.ix[np.random.randint(0, len(ts) - 1, 400)] repr(ts).splitlines()[-1] + def test_timeseries_periodindex(self): + # GH2891 + import pickle + from pandas import period_range + prng = period_range('1/1/2011', '1/1/2012', freq='M') + ts = Series(np.random.randn(len(prng)), prng) + new_ts = pickle.loads(pickle.dumps(ts)) + self.assertEqual(new_ts.index.freq,'M') + + def test_iter(self): for i, val in enumerate(self.series): self.assertEqual(val, self.series[i]) diff --git a/pandas/tseries/period.py b/pandas/tseries/period.py index 1e9aad7cf2d7b..51903b7179822 100644 --- a/pandas/tseries/period.py +++ b/pandas/tseries/period.py @@ -1115,6 +1115,25 @@ def append(self, other): for x in to_concat] return Index(com._concat_compat(to_concat), name=name) + def __reduce__(self): + """Necessary for making this object picklable""" + object_state = list(np.ndarray.__reduce__(self)) + subclass_state = (self.name, self.freq) + object_state[2] = (object_state[2], subclass_state) + return tuple(object_state) + + def __setstate__(self, state): + """Necessary for making this object picklable""" + if len(state) == 2: + nd_state, own_state = state + np.ndarray.__setstate__(self, nd_state) + self.name = own_state[0] + try: # backcompat + self.freq = own_state[1] + except: + pass + else: # pragma: no cover + np.ndarray.__setstate__(self, state) def _get_ordinal_range(start, end, periods, freq): if com._count_not_none(start, end, periods) < 2: diff --git a/pandas/tseries/tests/test_period.py b/pandas/tseries/tests/test_period.py index 3bb9008f7b863..8bce80493906b 100644 --- a/pandas/tseries/tests/test_period.py +++ b/pandas/tseries/tests/test_period.py @@ -1946,6 +1946,12 @@ def test_append_concat(self): self.assert_(isinstance(result.index, PeriodIndex)) self.assertEquals(result.index[0], s1.index[0]) + def test_pickle_freq(self): + # GH2891 + import pickle + prng = period_range('1/1/2011', '1/1/2012', freq='M') + new_prng = pickle.loads(pickle.dumps(prng)) + self.assertEqual(new_prng.freq,'M') def _permute(obj): return obj.take(np.random.permutation(len(obj)))