-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
TST: assert reading of legacy pickles against current data #61792
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
Open
jorisvandenbossche
wants to merge
1
commit into
pandas-dev:main
Choose a base branch
from
jorisvandenbossche:tests-pickle-legacy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+59
−12
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
) | ||
import pandas._testing as tm | ||
from pandas.tests.io.generate_legacy_storage_files import create_pickle_data | ||
from pandas.util.version import Version | ||
|
||
import pandas.io.common as icom | ||
from pandas.tseries.offsets import ( | ||
|
@@ -56,7 +57,7 @@ | |
# --------------------- | ||
def compare_element(result, expected, typ): | ||
if isinstance(expected, Index): | ||
tm.assert_index_equal(expected, result) | ||
tm.assert_index_equal(result, expected) | ||
return | ||
|
||
if typ.startswith("sp_"): | ||
|
@@ -81,15 +82,39 @@ def test_pickles(datapath): | |
if not is_platform_little_endian(): | ||
pytest.skip("known failure on non-little endian") | ||
|
||
current_data = create_pickle_data() | ||
|
||
# For loop for compat with --strict-data-files | ||
for legacy_pickle in Path(__file__).parent.glob("data/legacy_pickle/*/*.p*kl*"): | ||
legacy_version = Version(legacy_pickle.parent.name) | ||
legacy_pickle = datapath(legacy_pickle) | ||
|
||
data = pd.read_pickle(legacy_pickle) | ||
|
||
for typ, dv in data.items(): | ||
for dt, result in dv.items(): | ||
expected = data[typ][dt] | ||
expected = current_data[typ][dt] | ||
|
||
if ( | ||
typ == "timestamp" | ||
and dt in ("tz", "both") | ||
and legacy_version < Version("1.3.0") | ||
): | ||
# convert to wall time | ||
# (bug since pandas 2.0 that tz gets dropped for older pickle files) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there an issue ref for this |
||
expected = expected.tz_convert(None) | ||
|
||
if typ in ("frame", "sp_frame"): | ||
expected.columns = expected.columns.astype("object") | ||
|
||
if typ == "frame" and dt == "mi": | ||
expected.index = expected.index.set_levels( | ||
[level.astype("object") for level in expected.index.levels], | ||
) | ||
if typ == "mi": | ||
expected = expected.set_levels( | ||
[level.astype("object") for level in expected.levels], | ||
) | ||
|
||
if typ == "series" and dt == "ts": | ||
# GH 7748 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jorisvandenbossche to get the old behavior here, the code changes are a bit more involved. I've not got round to reviewing all the migration guides/release notes yet. Is this included? if not, should it be?