Skip to content

Commit efd8b3a

Browse files
committed
REGR: unpickling in 1.3.0 DataFrame created in 1.2.x pandas-dev#42345
1 parent dad3e7f commit efd8b3a

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

doc/source/whatsnew/v1.3.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ including other versions of pandas.
1515
Fixed regressions
1616
~~~~~~~~~~~~~~~~~
1717
- Pandas could not be built on PyPy (:issue:`42355`)
18+
- :class:`DataFrame` constructed in with an older version of pandas could not be unpickled (:issue:`42345`)
1819
-
1920

2021
.. ---------------------------------------------------------------------------

pandas/_libs/internals.pyx

+6-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,12 @@ cdef class BlockManager:
569569
public bint _known_consolidated, _is_consolidated
570570
public ndarray _blknos, _blklocs
571571

572-
def __cinit__(self, blocks, axes, verify_integrity=True):
572+
def __cinit__(self, blocks=None, axes=None, verify_integrity=True):
573+
# None as defaults for unpickling GH#42345
574+
if blocks is None:
575+
# TODO: how does this affect perf?
576+
return
577+
573578
if isinstance(blocks, list):
574579
# Backward compat for e.g. pyarrow
575580
blocks = tuple(blocks)
Binary file not shown.

pandas/tests/io/test_pickle.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ def compare_index_period(result, expected, typ, version):
163163
tm.assert_index_equal(result.shift(2), expected.shift(2))
164164

165165

166-
files = glob.glob(
167-
os.path.join(os.path.dirname(__file__), "data", "legacy_pickle", "*", "*.pickle")
168-
)
166+
here = os.path.dirname(__file__)
167+
legacy_dirname = os.path.join(here, "data", "legacy_pickle")
168+
files = glob.glob(os.path.join(legacy_dirname, "*", "*.pickle"))
169169

170170

171171
@pytest.fixture(params=files)
@@ -635,3 +635,13 @@ def test_pickle_big_dataframe_compression(protocol, compression):
635635
partial(pd.read_pickle, compression=compression),
636636
)
637637
tm.assert_frame_equal(df, result)
638+
639+
640+
def test_pickle_frame_v124_unpickle_130():
641+
# GH#42345 DataFrame created in 1.2.x, unpickle in 1.3.x
642+
path = os.path.join(legacy_dirname, "1.2.4", "empty_frame_v1_2_4-GH#42345.pkl")
643+
with open(path, "rb") as fd:
644+
df = pickle.load(fd)
645+
646+
expected = pd.DataFrame()
647+
tm.assert_frame_equal(df, expected)

0 commit comments

Comments
 (0)