Skip to content

Commit 3cc4765

Browse files
committed
pickle changes
1 parent fc34fe8 commit 3cc4765

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

pandas/tests/io/generate_legacy_storage_files.py

+54-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
cd ~/
1212
1313
$ python pandas/pandas/tests/io/generate_legacy_storage_files.py \
14-
pandas/pandas/tests/io/data/legacy_pickle/0.18.1/ pickle
14+
pandas/pandas/tests/io/data/legacy_pickle/0.20.3/ pickle
1515
1616
This script generates a storage file for the current arch, system,
1717
and python version
1818
pandas version: 0.20.3
19-
output dir : pandas/pandas/tests/io/data/legacy_pickle/0.18.1/
19+
output dir : pandas/pandas/tests/io/data/legacy_pickle/0.20.3/
2020
storage format: pickle
2121
created pickle file: 0.20.3_x86_64_darwin_3.5.2.pickle
2222
@@ -54,6 +54,7 @@
5454
RangeIndex,
5555
Series,
5656
Timestamp,
57+
bdate_range,
5758
date_range,
5859
period_range,
5960
timedelta_range,
@@ -83,9 +84,56 @@
8384
YearEnd,
8485
)
8586

87+
try:
88+
from pandas.arrays import SparseArray
89+
except ImportError:
90+
from pandas.core.sparse.api import SparseArray
91+
92+
8693
_loose_version = LooseVersion(pandas.__version__)
8794

8895

96+
def _create_sp_series():
97+
nan = np.nan
98+
99+
# nan-based
100+
arr = np.arange(15, dtype=np.float64)
101+
arr[7:12] = nan
102+
arr[-1:] = nan
103+
104+
bseries = Series(SparseArray(arr, kind="block"))
105+
bseries.name = "bseries"
106+
return bseries
107+
108+
109+
def _create_sp_tsseries():
110+
nan = np.nan
111+
112+
# nan-based
113+
arr = np.arange(15, dtype=np.float64)
114+
arr[7:12] = nan
115+
arr[-1:] = nan
116+
117+
date_index = bdate_range("1/1/2011", periods=len(arr))
118+
bseries = Series(SparseArray(arr, kind="block"), index=date_index)
119+
bseries.name = "btsseries"
120+
return bseries
121+
122+
123+
def _create_sp_frame():
124+
nan = np.nan
125+
126+
data = {
127+
"A": [nan, nan, nan, 0, 1, 2, 3, 4, 5, 6],
128+
"B": [0, 1, 2, nan, nan, nan, 3, 4, 5, 6],
129+
"C": np.arange(10).astype(np.int64),
130+
"D": [0, 1, 2, 3, 4, 5, nan, nan, nan, nan],
131+
}
132+
133+
dates = bdate_range("1/1/2011", periods=10)
134+
return DataFrame(data, index=dates).apply(SparseArray)
135+
136+
89137
def create_data():
90138
""" create the pickle/msgpack data """
91139

@@ -243,6 +291,8 @@ def create_data():
243291
index=index,
244292
scalars=scalars,
245293
mi=mi,
294+
sp_series=dict(float=_create_sp_series(), ts=_create_sp_tsseries()),
295+
sp_frame=dict(float=_create_sp_frame()),
246296
cat=cat,
247297
timestamp=timestamp,
248298
offsets=off,
@@ -262,6 +312,8 @@ def _u(x):
262312
def create_msgpack_data():
263313
data = create_data()
264314
# Not supported
315+
del data["sp_series"]
316+
del data["sp_frame"]
265317
del data["series"]["cat"]
266318
del data["series"]["period"]
267319
del data["frame"]["cat_onecol"]

pandas/tests/io/test_pickle.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def compare_element(result, expected, typ, version=None):
4949
return
5050

5151
if typ.startswith("sp_"):
52-
comparator = getattr(tm, "assert_{typ}_equal".format(typ=typ))
53-
comparator(result, expected, exact_indices=False)
52+
comparator = tm.assert_equal
53+
comparator(result, expected)
5454
elif typ == "timestamp":
5555
if expected is pd.NaT:
5656
assert result is pd.NaT

0 commit comments

Comments
 (0)