Skip to content

Commit aa04812

Browse files
committed
update legacy_storage for pickles
1 parent 0525684 commit aa04812

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

doc/source/whatsnew/v0.17.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ Other enhancements
198198

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

201+
- Support pickling of ``Period`` objects (:issue:`10439`)
202+
201203
.. _whatsnew_0170.api:
202204

203205
.. _whatsnew_0170.api_breaking:
Binary file not shown.
Binary file not shown.

pandas/io/tests/generate_legacy_storage_files.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from pandas import (Series, TimeSeries, DataFrame, Panel,
55
SparseSeries, SparseTimeSeries, SparseDataFrame, SparsePanel,
66
Index, MultiIndex, PeriodIndex, bdate_range, to_msgpack,
7-
date_range, period_range, bdate_range, Timestamp, Categorical)
7+
date_range, period_range, bdate_range, Timestamp, Categorical,
8+
Period)
89
import os
910
import sys
1011
import numpy as np
@@ -63,6 +64,10 @@ def create_data():
6364
'E': [0., 1, Timestamp('20100101'), 'foo', 2.]
6465
}
6566

67+
scalars = dict(timestamp=Timestamp('20130101'))
68+
if LooseVersion(pandas.__version__) >= '0.17.0':
69+
scalars['period'] = Period('2012','M')
70+
6671
index = dict(int=Index(np.arange(10)),
6772
date=date_range('20130101', periods=10),
6873
period=period_range('2013-01-01', freq='M', periods=10))
@@ -78,8 +83,9 @@ def create_data():
7883
index=MultiIndex.from_tuples(tuple(zip(*[[1, 1, 2, 2, 2], [3, 4, 3, 4, 5]])),
7984
names=['one', 'two'])),
8085
dup=Series(np.arange(5).astype(np.float64), index=['A', 'B', 'C', 'D', 'A']),
81-
cat=Series(Categorical(['foo', 'bar', 'baz'])),
82-
per=Series([Period('2000Q1')] * 5))
86+
cat=Series(Categorical(['foo', 'bar', 'baz'])))
87+
if LooseVersion(pandas.__version__) >= '0.17.0':
88+
series['period'] = Series([Period('2000Q1')] * 5)
8389

8490
mixed_dup_df = DataFrame(data)
8591
mixed_dup_df.columns = list("ABCDA")
@@ -108,6 +114,7 @@ def create_data():
108114
frame=frame,
109115
panel=panel,
110116
index=index,
117+
scalars=scalars,
111118
mi=mi,
112119
sp_series=dict(float=_create_sp_series(),
113120
ts=_create_sp_tsseries()),

pandas/io/tests/test_pickle.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def compare_element(self, typ, result, expected):
4848
comparator = getattr(test_sparse,"assert_%s_equal" % typ)
4949
comparator(result,expected,exact_indices=False)
5050
else:
51-
comparator = getattr(tm,"assert_%s_equal" % typ)
51+
comparator = getattr(tm,"assert_%s_equal" % typ,tm.assert_almost_equal)
5252
comparator(result,expected)
5353

5454
def compare(self, vf):

pandas/tseries/tests/test_period.py

-6
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
77
"""
88

9-
import pickle
10-
import os
11-
129
from datetime import datetime, date, timedelta
1310

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

24752472
def test_pickle_freq(self):
24762473
# GH2891
2477-
import pickle
24782474
prng = period_range('1/1/2011', '1/1/2012', freq='M')
24792475
new_prng = self.round_trip_pickle(prng)
24802476
self.assertEqual(new_prng.freq,'M')
@@ -2541,9 +2537,7 @@ def test_searchsorted(self):
25412537

25422538
def test_round_trip(self):
25432539

2544-
import pickle
25452540
p = Period('2000Q1')
2546-
25472541
new_p = self.round_trip_pickle(p)
25482542
self.assertEqual(new_p, p)
25492543

0 commit comments

Comments
 (0)