Skip to content

Commit

Permalink
REGR: Fix reading old pickles from pandas 1.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
lithomas1 committed Dec 3, 2023
1 parent 762b61d commit efed9ad
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.1.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ including other versions of pandas.

Fixed regressions
~~~~~~~~~~~~~~~~~
-
- Fixed regression when trying to read a pickled pandas :class:`DataFrame` from pandas 1.3 (:issue:`55137`)
-

.. ---------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2557,6 +2557,11 @@ def new_block(
# - check_ndim/ensure_block_shape already checked
# - maybe_coerce_values already called/unnecessary
klass = get_block_type(values.dtype)

# Old pandas (<=1.3.0) will call this function with placements
# that aren't necessarily BlockPlacements when unpickling
if not isinstance(placement, BlockPlacement):
placement = BlockPlacement(placement)
return klass(values, ndim=ndim, placement=placement, refs=refs)


Expand Down
Binary file not shown.
9 changes: 8 additions & 1 deletion pandas/tests/io/generate_legacy_storage_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
import platform as pl
import sys

# Remove script directory from path, otherwise Python will try to
# import the JSON test directory as the json module
sys.path.pop(0)

import numpy as np

import pandas
Expand Down Expand Up @@ -314,7 +318,7 @@ def write_legacy_pickles(output_dir):

def write_legacy_file():
# force our cwd to be the first searched
sys.path.insert(0, ".")
sys.path.insert(0, "")

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

if not os.path.exists(output_dir):
os.mkdir(output_dir)

if storage_type == "pickle":
write_legacy_pickles(output_dir=output_dir)
else:
Expand Down

0 comments on commit efed9ad

Please sign in to comment.