Skip to content

Commit 46cd7f0

Browse files
WillAydjreback
authored andcommitted
Removed Panel Kludge from Pickle/Msgpack tests (#27082)
1 parent b387da8 commit 46cd7f0

File tree

90 files changed

+40
-136
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+40
-136
lines changed

doc/source/user_guide/io.rst

+5-10

doc/source/whatsnew/v0.25.0.rst

+5

pandas/io/packers.py

+5
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ def read_msgpack(path_or_buf, encoding='utf-8', iterator=False, **kwargs):
134134
Returns
135135
-------
136136
obj : same type as object stored in file
137+
138+
Notes
139+
-----
140+
read_msgpack is only guaranteed to be backwards compatible to pandas
141+
0.20.3.
137142
"""
138143
path_or_buf, _, _, should_close = get_filepath_or_buffer(path_or_buf)
139144
if iterator:

pandas/io/pickle.py

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ def read_pickle(path, compression='infer'):
116116
read_sql : Read SQL query or database table into a DataFrame.
117117
read_parquet : Load a parquet object, returning a DataFrame.
118118
119+
Notes
120+
-----
121+
read_pickle is only guaranteed to be backwards compatible to pandas 0.20.3.
122+
119123
Examples
120124
--------
121125
>>> original_df = pd.DataFrame({"foo": range(5), "bar": range(5, 10)})
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

pandas/tests/io/generate_legacy_storage_files.py

+11-34
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
self-contained to write legacy storage (pickle/msgpack) files
55
66
To use this script. Create an environment where you want
7-
generate pickles, say its for 0.18.1, with your pandas clone
7+
generate pickles, say its for 0.20.3, with your pandas clone
88
in ~/pandas
99
10-
. activate pandas_0.18.1
10+
. activate pandas_0.20.3
1111
cd ~/
1212
1313
$ python pandas/pandas/tests/io/generate_legacy_storage_files.py \
1414
pandas/pandas/tests/io/data/legacy_pickle/0.18.1/ pickle
1515
1616
This script generates a storage file for the current arch, system,
1717
and python version
18-
pandas version: 0.18.1
18+
pandas version: 0.20.3
1919
output dir : pandas/pandas/tests/io/data/legacy_pickle/0.18.1/
2020
storage format: pickle
21-
created pickle file: 0.18.1_x86_64_darwin_3.5.2.pickle
21+
created pickle file: 0.20.3_x86_64_darwin_3.5.2.pickle
2222
2323
The idea here is you are using the *current* version of the
2424
generate_legacy_storage_files with an *older* version of pandas to
@@ -45,7 +45,7 @@
4545

4646
import pandas
4747
from pandas import (
48-
Categorical, DataFrame, Index, MultiIndex, NaT, Period, Series,
48+
Categorical, DataFrame, Index, MultiIndex, NaT, Period, RangeIndex, Series,
4949
SparseDataFrame, SparseSeries, Timestamp, bdate_range, date_range,
5050
period_range, timedelta_range, to_msgpack)
5151

@@ -118,9 +118,7 @@ def create_data():
118118
uint=Index(np.arange(10, dtype=np.uint64)),
119119
timedelta=timedelta_range('00:00:00', freq='30T', periods=10))
120120

121-
if _loose_version >= LooseVersion('0.18'):
122-
from pandas import RangeIndex
123-
index['range'] = RangeIndex(10)
121+
index['range'] = RangeIndex(10)
124122

125123
if _loose_version >= LooseVersion('0.21'):
126124
from pandas import interval_range
@@ -191,14 +189,9 @@ def create_data():
191189
nat=NaT,
192190
tz=Timestamp('2011-01-01', tz='US/Eastern'))
193191

194-
if _loose_version < LooseVersion('0.19.2'):
195-
timestamp['freq'] = Timestamp('2011-01-01', offset='D')
196-
timestamp['both'] = Timestamp('2011-01-01', tz='Asia/Tokyo',
197-
offset='M')
198-
else:
199-
timestamp['freq'] = Timestamp('2011-01-01', freq='D')
200-
timestamp['both'] = Timestamp('2011-01-01', tz='Asia/Tokyo',
201-
freq='M')
192+
timestamp['freq'] = Timestamp('2011-01-01', freq='D')
193+
timestamp['both'] = Timestamp('2011-01-01', tz='Asia/Tokyo',
194+
freq='M')
202195

203196
off = {'DateOffset': DateOffset(years=1),
204197
'DateOffset_h_ns': DateOffset(hour=6, nanoseconds=5824),
@@ -239,14 +232,6 @@ def create_data():
239232
def create_pickle_data():
240233
data = create_data()
241234

242-
# Pre-0.14.1 versions generated non-unpicklable mixed-type frames and
243-
# panels if their columns/items were non-unique.
244-
if _loose_version < LooseVersion('0.14.1'):
245-
del data['frame']['mixed_dup']
246-
del data['panel']['mixed_dup']
247-
if _loose_version < LooseVersion('0.17.0'):
248-
del data['series']['period']
249-
del data['scalars']['period']
250235
return data
251236

252237

@@ -256,14 +241,6 @@ def _u(x):
256241

257242
def create_msgpack_data():
258243
data = create_data()
259-
if _loose_version < LooseVersion('0.17.0'):
260-
del data['frame']['mixed_dup']
261-
del data['panel']['mixed_dup']
262-
del data['frame']['dup']
263-
del data['panel']['dup']
264-
if _loose_version < LooseVersion('0.18.0'):
265-
del data['series']['dt_tz']
266-
del data['frame']['dt_mixed_tzs']
267244
# Not supported
268245
del data['sp_series']
269246
del data['sp_frame']
@@ -272,7 +249,8 @@ def create_msgpack_data():
272249
del data['frame']['cat_onecol']
273250
del data['frame']['cat_and_float']
274251
del data['scalars']['period']
275-
if _loose_version < LooseVersion('0.23.0'):
252+
if _loose_version >= LooseVersion('0.21') and (
253+
_loose_version < LooseVersion('0.23.0')):
276254
del data['index']['interval']
277255
del data['offsets']
278256
return _u(data)
@@ -285,7 +263,6 @@ def platform_name():
285263

286264
def write_legacy_pickles(output_dir):
287265

288-
# make sure we are < 0.13 compat (in py3)
289266
version = pandas.__version__
290267

291268
print("This script generates a storage file for the current arch, system, "

pandas/tests/io/test_packers.py

+3-37
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import datetime
2-
from distutils.version import LooseVersion
32
import glob
43
from io import BytesIO
54
import os
@@ -84,7 +83,6 @@ def check_arbitrary(a, b):
8483
assert(a == b)
8584

8685

87-
@pytest.mark.filterwarnings("ignore:\\nPanel:FutureWarning")
8886
class TestPackers:
8987

9088
def setup_method(self, method):
@@ -99,7 +97,6 @@ def encode_decode(self, x, compress=None, **kwargs):
9997
return read_msgpack(p, **kwargs)
10098

10199

102-
@pytest.mark.filterwarnings("ignore:\\nPanel:FutureWarning")
103100
class TestAPI(TestPackers):
104101

105102
def test_string_io(self):
@@ -463,7 +460,6 @@ def test_basic(self):
463460
assert_categorical_equal(i, i_rec)
464461

465462

466-
@pytest.mark.filterwarnings("ignore:\\nPanel:FutureWarning")
467463
class TestNDFrame(TestPackers):
468464

469465
def setup_method(self, method):
@@ -842,7 +838,6 @@ def legacy_packer(request, datapath):
842838
return datapath(request.param)
843839

844840

845-
@pytest.mark.filterwarnings("ignore:\\nPanel:FutureWarning")
846841
@pytest.mark.filterwarnings("ignore:Sparse:FutureWarning")
847842
class TestMsgpack:
848843
"""
@@ -858,31 +853,19 @@ class TestMsgpack:
858853
minimum_structure = {'series': ['float', 'int', 'mixed',
859854
'ts', 'mi', 'dup'],
860855
'frame': ['float', 'int', 'mixed', 'mi'],
861-
'panel': ['float'],
862856
'index': ['int', 'date', 'period'],
863857
'mi': ['reg2']}
864858

865859
def check_min_structure(self, data, version):
866860
for typ, v in self.minimum_structure.items():
867-
if typ == "panel":
868-
# FIXME: kludge; get this key out of the legacy file
869-
continue
870861

871862
assert typ in data, '"{0}" not found in unpacked data'.format(typ)
872863
for kind in v:
873864
msg = '"{0}" not found in data["{1}"]'.format(kind, typ)
874865
assert kind in data[typ], msg
875866

876867
def compare(self, current_data, all_data, vf, version):
877-
# GH12277 encoding default used to be latin-1, now utf-8
878-
if LooseVersion(version) < LooseVersion('0.18.0'):
879-
data = read_msgpack(vf, encoding='latin-1')
880-
else:
881-
data = read_msgpack(vf)
882-
883-
if "panel" in data:
884-
# FIXME: kludge; get the key out of the stored file
885-
del data["panel"]
868+
data = read_msgpack(vf)
886869

887870
self.check_min_structure(data, version)
888871
for typ, dv in data.items():
@@ -909,33 +892,16 @@ def compare(self, current_data, all_data, vf, version):
909892
return data
910893

911894
def compare_series_dt_tz(self, result, expected, typ, version):
912-
# 8260
913-
# dtype is object < 0.17.0
914-
if LooseVersion(version) < LooseVersion('0.17.0'):
915-
expected = expected.astype(object)
916-
tm.assert_series_equal(result, expected)
917-
else:
918-
tm.assert_series_equal(result, expected)
895+
tm.assert_series_equal(result, expected)
919896

920897
def compare_frame_dt_mixed_tzs(self, result, expected, typ, version):
921-
# 8260
922-
# dtype is object < 0.17.0
923-
if LooseVersion(version) < LooseVersion('0.17.0'):
924-
expected = expected.astype(object)
925-
tm.assert_frame_equal(result, expected)
926-
else:
927-
tm.assert_frame_equal(result, expected)
898+
tm.assert_frame_equal(result, expected)
928899

929900
def test_msgpacks_legacy(self, current_packers_data, all_packers_data,
930901
legacy_packer, datapath):
931902

932903
version = os.path.basename(os.path.dirname(legacy_packer))
933904

934-
# GH12142 0.17 files packed in P2 can't be read in P3
935-
if (version.startswith('0.17.') and
936-
legacy_packer.split('.')[-4][-1] == '2'):
937-
msg = "Files packed in Py2 can't be read in Py3 ({})"
938-
pytest.skip(msg.format(version))
939905
try:
940906
with catch_warnings(record=True):
941907
self.compare(current_packers_data, all_packers_data,

pandas/tests/io/test_pickle.py

+7-55
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
3. Move the created pickle to "data/legacy_pickle/<version>" directory.
1212
"""
1313
import bz2
14-
from distutils.version import LooseVersion
1514
import glob
1615
import gzip
1716
import lzma
@@ -69,18 +68,8 @@ def compare(data, vf, version):
6968

7069
m = globals()
7170
for typ, dv in data.items():
72-
if typ == "panel":
73-
# FIXME: kludge; get this key out of the legacy file
74-
continue
75-
7671
for dt, result in dv.items():
77-
try:
78-
expected = data[typ][dt]
79-
except (KeyError):
80-
if version in ('0.10.1', '0.11.0') and dt == 'reg':
81-
break
82-
else:
83-
raise
72+
expected = data[typ][dt]
8473

8574
# use a specific comparator
8675
# if available
@@ -92,12 +81,7 @@ def compare(data, vf, version):
9281

9382

9483
def compare_sp_series_ts(res, exp, typ, version):
95-
# SparseTimeSeries integrated into SparseSeries in 0.12.0
96-
# and deprecated in 0.17.0
97-
if version and LooseVersion(version) <= LooseVersion("0.12.0"):
98-
tm.assert_sp_series_equal(res, exp, check_series_type=False)
99-
else:
100-
tm.assert_sp_series_equal(res, exp)
84+
tm.assert_sp_series_equal(res, exp)
10185

10286

10387
def compare_series_ts(result, expected, typ, version):
@@ -121,47 +105,19 @@ def compare_series_ts(result, expected, typ, version):
121105

122106

123107
def compare_series_dt_tz(result, expected, typ, version):
124-
# 8260
125-
# dtype is object < 0.17.0
126-
if LooseVersion(version) < LooseVersion('0.17.0'):
127-
expected = expected.astype(object)
128-
tm.assert_series_equal(result, expected)
129-
else:
130-
tm.assert_series_equal(result, expected)
108+
tm.assert_series_equal(result, expected)
131109

132110

133111
def compare_series_cat(result, expected, typ, version):
134-
# Categorical dtype is added in 0.15.0
135-
# ordered is changed in 0.16.0
136-
if LooseVersion(version) < LooseVersion('0.15.0'):
137-
tm.assert_series_equal(result, expected, check_dtype=False,
138-
check_categorical=False)
139-
elif LooseVersion(version) < LooseVersion('0.16.0'):
140-
tm.assert_series_equal(result, expected, check_categorical=False)
141-
else:
142-
tm.assert_series_equal(result, expected)
112+
tm.assert_series_equal(result, expected)
143113

144114

145115
def compare_frame_dt_mixed_tzs(result, expected, typ, version):
146-
# 8260
147-
# dtype is object < 0.17.0
148-
if LooseVersion(version) < LooseVersion('0.17.0'):
149-
expected = expected.astype(object)
150-
tm.assert_frame_equal(result, expected)
151-
else:
152-
tm.assert_frame_equal(result, expected)
116+
tm.assert_frame_equal(result, expected)
153117

154118

155119
def compare_frame_cat_onecol(result, expected, typ, version):
156-
# Categorical dtype is added in 0.15.0
157-
# ordered is changed in 0.16.0
158-
if LooseVersion(version) < LooseVersion('0.15.0'):
159-
tm.assert_frame_equal(result, expected, check_dtype=False,
160-
check_categorical=False)
161-
elif LooseVersion(version) < LooseVersion('0.16.0'):
162-
tm.assert_frame_equal(result, expected, check_categorical=False)
163-
else:
164-
tm.assert_frame_equal(result, expected)
120+
tm.assert_frame_equal(result, expected)
165121

166122

167123
def compare_frame_cat_and_float(result, expected, typ, version):
@@ -177,11 +133,7 @@ def compare_index_period(result, expected, typ, version):
177133

178134

179135
def compare_sp_frame_float(result, expected, typ, version):
180-
if LooseVersion(version) <= LooseVersion('0.18.1'):
181-
tm.assert_sp_frame_equal(result, expected, exact_indices=False,
182-
check_dtype=False)
183-
else:
184-
tm.assert_sp_frame_equal(result, expected)
136+
tm.assert_sp_frame_equal(result, expected)
185137

186138

187139
files = glob.glob(os.path.join(os.path.dirname(__file__), "data",

0 commit comments

Comments
 (0)