Skip to content

Commit db94793

Browse files
lithomas1meeseeksmachine
authored andcommitted
Backport PR pandas-dev#56308: REGR: Fix reading old pickles from pandas 1.3.5
1 parent c6efdb0 commit db94793

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

doc/source/whatsnew/v2.1.4.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ including other versions of pandas.
1313

1414
Fixed regressions
1515
~~~~~~~~~~~~~~~~~
16-
-
16+
- Fixed regression when trying to read a pickled pandas :class:`DataFrame` from pandas 1.3 (:issue:`55137`)
1717
-
1818

1919
.. ---------------------------------------------------------------------------

pandas/compat/pickle_compat.py

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ def load_reduce(self):
6565
("pandas.core.sparse.array", "SparseArray"): ("pandas.core.arrays", "SparseArray"),
6666
# 15477
6767
("pandas.core.base", "FrozenNDArray"): ("numpy", "ndarray"),
68+
# Re-routing unpickle block logic to go through _unpickle_block instead
69+
# for pandas <= 1.3.5
70+
("pandas.core.internals.blocks", "new_block"): (
71+
"pandas._libs.internals",
72+
"_unpickle_block",
73+
),
6874
("pandas.core.indexes.frozen", "FrozenNDArray"): ("numpy", "ndarray"),
6975
("pandas.core.base", "FrozenList"): ("pandas.core.indexes.frozen", "FrozenList"),
7076
# 10890
Binary file not shown.

pandas/tests/io/generate_legacy_storage_files.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
import platform as pl
3939
import sys
4040

41+
# Remove script directory from path, otherwise Python will try to
42+
# import the JSON test directory as the json module
43+
sys.path.pop(0)
44+
4145
import numpy as np
4246

4347
import pandas
@@ -320,7 +324,7 @@ def write_legacy_pickles(output_dir):
320324

321325
def write_legacy_file():
322326
# force our cwd to be the first searched
323-
sys.path.insert(0, ".")
327+
sys.path.insert(0, "")
324328

325329
if not 3 <= len(sys.argv) <= 4:
326330
sys.exit(
@@ -331,6 +335,9 @@ def write_legacy_file():
331335
output_dir = str(sys.argv[1])
332336
storage_type = str(sys.argv[2])
333337

338+
if not os.path.exists(output_dir):
339+
os.mkdir(output_dir)
340+
334341
if storage_type == "pickle":
335342
write_legacy_pickles(output_dir=output_dir)
336343
else:

0 commit comments

Comments
 (0)