Skip to content

Commit

Permalink
Backport PR pandas-dev#42394: REGR: unpickling in 1.3.0 DataFrame cre…
Browse files Browse the repository at this point in the history
…ated in 1.2.x pandas-dev#42345
  • Loading branch information
jbrockmendel authored and meeseeksmachine committed Jul 6, 2021
1 parent 61afc70 commit 1f8e9a4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
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)

0 comments on commit 1f8e9a4

Please sign in to comment.