Skip to content

Commit 8a8a650

Browse files
committed
COMPAT: remove Categorical pickle compat with < 0.16
1 parent ea666da commit 8a8a650

File tree

5 files changed

+2
-145
lines changed

5 files changed

+2
-145
lines changed

doc/source/whatsnew/v1.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Deprecations
6161
Removal of prior version deprecations/changes
6262
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6363

64-
-
64+
- Ability to read pickles containing ``Categorical`` created with pre-0.16 version of pandas has been removed (:issue:xxxx).
6565
-
6666

6767
.. _whatsnew_1000.performance:

pandas/core/arrays/categorical.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -1368,24 +1368,7 @@ def __setstate__(self, state):
13681368
if not isinstance(state, dict):
13691369
raise Exception("invalid pickle state")
13701370

1371-
# Provide compatibility with pre-0.15.0 Categoricals.
1372-
if "_categories" not in state and "_levels" in state:
1373-
state["_categories"] = self.dtype.validate_categories(state.pop("_levels"))
1374-
if "_codes" not in state and "labels" in state:
1375-
state["_codes"] = coerce_indexer_dtype(
1376-
state.pop("labels"), state["_categories"]
1377-
)
1378-
1379-
# 0.16.0 ordered change
1380-
if "_ordered" not in state:
1381-
1382-
# >=15.0 < 0.16.0
1383-
if "ordered" in state:
1384-
state["_ordered"] = state.pop("ordered")
1385-
else:
1386-
state["_ordered"] = False
1387-
1388-
# 0.21.0 CategoricalDtype change
1371+
# compat with pre 0.21.0 CategoricalDtype change
13891372
if "_dtype" not in state:
13901373
state["_dtype"] = CategoricalDtype(state["_categories"], state["_ordered"])
13911374

pandas/tests/io/data/categorical_0_14_1.pickle

-94
This file was deleted.
-392 Bytes
Binary file not shown.

pandas/tests/io/test_pickle.py

-32
Original file line numberDiff line numberDiff line change
@@ -193,38 +193,6 @@ def python_unpickler(path):
193193
compare_element(result, expected, typ)
194194

195195

196-
def test_pickle_v0_14_1(datapath):
197-
198-
cat = pd.Categorical(
199-
values=["a", "b", "c"], ordered=False, categories=["a", "b", "c", "d"]
200-
)
201-
pickle_path = datapath("io", "data", "categorical_0_14_1.pickle")
202-
# This code was executed once on v0.14.1 to generate the pickle:
203-
#
204-
# cat = Categorical(labels=np.arange(3), levels=['a', 'b', 'c', 'd'],
205-
# name='foobar')
206-
# with open(pickle_path, 'wb') as f: pickle.dump(cat, f)
207-
#
208-
tm.assert_categorical_equal(cat, pd.read_pickle(pickle_path))
209-
210-
211-
def test_pickle_v0_15_2(datapath):
212-
# ordered -> _ordered
213-
# GH 9347
214-
215-
cat = pd.Categorical(
216-
values=["a", "b", "c"], ordered=False, categories=["a", "b", "c", "d"]
217-
)
218-
pickle_path = datapath("io", "data", "categorical_0_15_2.pickle")
219-
# This code was executed once on v0.15.2 to generate the pickle:
220-
#
221-
# cat = Categorical(labels=np.arange(3), levels=['a', 'b', 'c', 'd'],
222-
# name='foobar')
223-
# with open(pickle_path, 'wb') as f: pickle.dump(cat, f)
224-
#
225-
tm.assert_categorical_equal(cat, pd.read_pickle(pickle_path))
226-
227-
228196
def test_pickle_path_pathlib():
229197
df = tm.makeDataFrame()
230198
result = tm.round_trip_pathlib(df.to_pickle, pd.read_pickle)

0 commit comments

Comments
 (0)