Skip to content

Commit 0d8e0a4

Browse files
authored
REGR: Fix reading old pickles from pandas 1.3.5 (#56308)
* REGR: Fix reading old pickles from pandas 1.3.5 * Use pickle compat * extraneous space
1 parent daa9cdb commit 0d8e0a4

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) -> None:
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
@@ -314,7 +318,7 @@ def write_legacy_pickles(output_dir):
314318

315319
def write_legacy_file():
316320
# force our cwd to be the first searched
317-
sys.path.insert(0, ".")
321+
sys.path.insert(0, "")
318322

319323
if not 3 <= len(sys.argv) <= 4:
320324
sys.exit(
@@ -325,6 +329,9 @@ def write_legacy_file():
325329
output_dir = str(sys.argv[1])
326330
storage_type = str(sys.argv[2])
327331

332+
if not os.path.exists(output_dir):
333+
os.mkdir(output_dir)
334+
328335
if storage_type == "pickle":
329336
write_legacy_pickles(output_dir=output_dir)
330337
else:

0 commit comments

Comments
 (0)