Skip to content

Commit f8c83b6

Browse files
authored
REGR: unpickling in 1.3.0 DataFrame created in 1.2.x #42345 (#42394)
1 parent a69603d commit f8c83b6

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 with 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+
# This adds 1-2 microseconds to DataFrame(np.array([]))
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
@@ -162,9 +162,9 @@ def compare_index_period(result, expected, typ, version):
162162
tm.assert_index_equal(result.shift(2), expected.shift(2))
163163

164164

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

169169

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

0 commit comments

Comments
 (0)