Skip to content

Commit 37e5881

Browse files
committed
COMPAT: remove Categorical pickle compat with < 0.16
1 parent 9f93d57 commit 37e5881

File tree

7 files changed

+4
-145
lines changed

7 files changed

+4
-145
lines changed

doc/source/whatsnew/v1.0.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ Removal of prior version deprecations/changes
6767
- :meth:`pandas.Series.str.cat` does not accept list-likes *within* list-likes anymore (:issue:`27611`)
6868
- Removed the previously deprecated :meth:`ExtensionArray._formatting_values`. Use :attr:`ExtensionArray._formatter` instead. (:issue:`23601`)
6969
- Removed the previously deprecated ``IntervalIndex.from_intervals`` in favor of the :class:`IntervalIndex` constructor (:issue:`19263`)
70+
- Ability to read pickles containing ``Categorical`` created with pre-0.16 version of pandas has been removed (:issue:`27538`).
71+
-
7072

7173
.. _whatsnew_1000.performance:
7274

pandas/core/arrays/categorical.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -1350,24 +1350,7 @@ def __setstate__(self, state):
13501350
if not isinstance(state, dict):
13511351
raise Exception("invalid pickle state")
13521352

1353-
# Provide compatibility with pre-0.15.0 Categoricals.
1354-
if "_categories" not in state and "_levels" in state:
1355-
state["_categories"] = self.dtype.validate_categories(state.pop("_levels"))
1356-
if "_codes" not in state and "labels" in state:
1357-
state["_codes"] = coerce_indexer_dtype(
1358-
state.pop("labels"), state["_categories"]
1359-
)
1360-
1361-
# 0.16.0 ordered change
1362-
if "_ordered" not in state:
1363-
1364-
# >=15.0 < 0.16.0
1365-
if "ordered" in state:
1366-
state["_ordered"] = state.pop("ordered")
1367-
else:
1368-
state["_ordered"] = False
1369-
1370-
# 0.21.0 CategoricalDtype change
1353+
# compat with pre 0.21.0 CategoricalDtype change
13711354
if "_dtype" not in state:
13721355
state["_dtype"] = CategoricalDtype(state["_categories"], state["_ordered"])
13731356

578 Bytes
Binary file not shown.

pandas/tests/io/data/categorical_0_14_1.pickle

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

pandas/tests/io/test_common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def test_read_expands_user_home_dir(
222222
(pd.read_sas, "os", ("io", "sas", "data", "test1.sas7bdat")),
223223
(pd.read_json, "os", ("io", "json", "data", "tsframe_v012.json")),
224224
(pd.read_msgpack, "os", ("io", "msgpack", "data", "frame.mp")),
225-
(pd.read_pickle, "os", ("io", "data", "categorical_0_14_1.pickle")),
225+
(pd.read_pickle, "os", ("io", "data", "categorical.pickle")),
226226
],
227227
)
228228
def test_read_fspath_all(self, reader, module, path, datapath):

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)