8000 ENH: Period pickle by jreback · Pull Request #10866 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

ENH: Period pickle #10866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 20, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update legacy_storage for pickles
  • Loading branch information
jreback committed Aug 20, 2015
commit aa04812aa8da5505a52b094acffb8296f041b637
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ Other enhancements

``tolerance`` is also exposed by the lower level ``Index.get_indexer`` and ``Index.get_loc`` methods.

- Support pickling of ``Period`` objects (:issue:`10439`)

.. _whatsnew_0170.api:

.. _whatsnew_0170.api_breaking:
Expand Down
Binary file not shown.
Binary file not shown.
13 changes: 10 additions & 3 deletions pandas/io/tests/generate_legacy_storage_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from pandas import (Series, TimeSeries, DataFrame, Panel,
SparseSeries, SparseTimeSeries, SparseDataFrame, SparsePanel,
Index, MultiIndex, PeriodIndex, bdate_range, to_msgpack,
date_range, period_range, bdate_range, Timestamp, Categorical)
date_range, period_range, bdate_range, Timestamp, Categorical,
Period)
import os
import sys
import numpy as np
Expand Down Expand Up @@ -63,6 +64,10 @@ def create_data():
'E': [0., 1, Timestamp('20100101'), 'foo', 2.]
}

scalars = dict(timestamp=Timestamp('20130101'))
if LooseVersion(pandas.__version__) >= '0.17.0':
scalars['period'] = Period('2012','M')

index = dict(int=Index(np.arange(10)),
date=date_range('20130101', periods=10),
period=period_range('2013-01-01', freq='M', periods=10))
Expand All @@ -78,8 +83,9 @@ def create_data():
index=MultiIndex.from_tuples(tuple(zip(*[[1, 1, 2, 2, 2], [3, 4, 3, 4, 5]])),
names=['one', 'two'])),
dup=Series(np.arange(5).astype(np.float64), index=['A', 'B', 'C', 'D', 'A']),
cat=Series(Categorical(['foo', 'bar', 'baz'])),
per=Series([Period('2000Q1')] * 5))
cat=Series(Categorical(['foo', 'bar', 'baz'])))
if LooseVersion(pandas.__version__) >= '0.17.0':
series['period'] = Series([Period('2000Q1')] * 5)

mixed_dup_df = DataFrame(data)
mixed_dup_df.columns = list("ABCDA")
Expand Down Expand Up @@ -108,6 +114,7 @@ def create_data():
frame=frame,
panel=panel,
index=index,
scalars=scalars,
mi=mi,
sp_series=dict(float=_create_sp_series(),
ts=_create_sp_tsseries()),
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/tests/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def compare_element(self, typ, result, expected):
comparator = getattr(test_sparse,"assert_%s_equal" % typ)
comparator(result,expected,exact_indices=False)
else:
comparator = getattr(tm,"assert_%s_equal" % typ)
comparator = getattr(tm,"assert_%s_equal" % typ,tm.assert_almost_equal)
comparator(result,expected)

def compare(self, vf):
Expand Down
6 changes: 0 additions & 6 deletions pandas/tseries/tests/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

"""

import pickle
import os

from datetime import datetime, date, timedelta

from numpy.ma.testutils import assert_equal
Expand Down Expand Up @@ -2474,7 +2471,6 @@ def test_append_concat(self):

def test_pickle_freq(self):
# GH2891
import pickle
prng = period_range('1/1/2011', '1/1/2012', freq='M')
new_prng = self.round_trip_pickle(prng)
self.assertEqual(new_prng.freq,'M')
Expand Down Expand Up @@ -2541,9 +2537,7 @@ def test_searchsorted(self):

def test_round_trip(self):

import pickle
p = Period('2000Q1')

new_p = self.round_trip_pickle(p)
self.assertEqual(new_p, p)

Expand Down
0