Skip to content

Backport PR #42394 on branch 1.3.x (REGR: unpickling in 1.3.0 DataFrame created in 1.2.x #42345) #42416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.3.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ including other versions of pandas.
Fixed regressions
~~~~~~~~~~~~~~~~~
- Pandas could not be built on PyPy (:issue:`42355`)
- :class:`DataFrame` constructed with with an older version of pandas could not be unpickled (:issue:`42345`)
-

.. ---------------------------------------------------------------------------
Expand Down
7 changes: 6 additions & 1 deletion pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,12 @@ cdef class BlockManager:
public bint _known_consolidated, _is_consolidated
public ndarray _blknos, _blklocs

def __cinit__(self, blocks, axes, verify_integrity=True):
def __cinit__(self, blocks=None, axes=None, verify_integrity=True):
# None as defaults for unpickling GH#42345
if blocks is None:
# This adds 1-2 microseconds to DataFrame(np.array([]))
return

if isinstance(blocks, list):
# Backward compat for e.g. pyarrow
blocks = tuple(blocks)
Expand Down
Binary file not shown.
16 changes: 13 additions & 3 deletions pandas/tests/io/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ def compare_index_period(result, expected, typ, version):
tm.assert_index_equal(result.shift(2), expected.shift(2))


files = glob.glob(
os.path.join(os.path.dirname(__file__), "data", "legacy_pickle", "*", "*.pickle")
)
here = os.path.dirname(__file__)
legacy_dirname = os.path.join(here, "data", "legacy_pickle")
files = glob.glob(os.path.join(legacy_dirname, "*", "*.pickle"))


@pytest.fixture(params=files)
Expand Down Expand Up @@ -635,3 +635,13 @@ def test_pickle_big_dataframe_compression(protocol, compression):
partial(pd.read_pickle, compression=compression),
)
tm.assert_frame_equal(df, result)


def test_pickle_frame_v124_unpickle_130():
# GH#42345 DataFrame created in 1.2.x, unpickle in 1.3.x
path = os.path.join(legacy_dirname, "1.2.4", "empty_frame_v1_2_4-GH#42345.pkl")
with open(path, "rb") as fd:
df = pickle.load(fd)

expected = pd.DataFrame()
tm.assert_frame_equal(df, expected)