Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BUG: Fix metadata not roundtripping when pickling datetime#29555

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
seberg merged 8 commits intonumpy:mainfromMaanasArora:bug/datetime-metadata-warning
Aug 14, 2025

Conversation

@MaanasArora
Copy link
Contributor

@MaanasAroraMaanasArora commentedAug 13, 2025
edited
Loading

Fixes#29344.

It seems that for datetime dtypes,arraydescr_reduce was initializing a new mapping instead of setting toPy_None, and thenarraydescr_setstate just read it in. I set the metadata to and then checked forPy_None and refactored some of the logic to be clearer hopefully.

Adding a test. Thanks for reviewing!

@MaanasArora
Copy link
ContributorAuthor

Added test! Confirmed that it fails on main.

forprotoinrange(2,pickle.HIGHEST_PROTOCOL+1):
res=pickle.loads(pickle.dumps(dt,protocol=proto))
assert_equal(res,dt)
assertres.metadataisNone
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Since this test already has 7 other assertions above, any objection to just making it its own regression test:

--- a/numpy/_core/tests/test_datetime.py+++ b/numpy/_core/tests/test_datetime.py@@ -889,8 +889,8 @@ def test_pickle(self):                 b"I1\nI1\nI1\ntp7\ntp8\ntp9\nb."             assert_equal(pickle.loads(pkl), np.dtype('>M8[us]'))+    def test_gh_29555(self):         # check that dtype metadata round-trips when none-        # gh-29555         dt = np.dtype('>M8[us]')

Beyond that, the regression test does indeed seem to fail before/pass after the patch in my hands locally.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That seems nice, applied, thanks!

Copy link
Member

@sebergseberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The None reference is a bug but we can also just apply a suggestion even. Tylers test suggestion seems like a nice to have.

PyTuple_SET_ITEM(ret,0,PyDict_New());
}
else {
PyTuple_SET_ITEM(ret,0,Py_None);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This steals a reference to None! Otherwise LGTM, though.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Oh yes, sorry - fixed. Thanks!

charendian;
PyObject*endian_obj;
PyObject*subarray,*fields,*names=NULL,*metadata=NULL;
PyObject*old_metadata,*new_metadata;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Would probably move these down, but doesn't matter (and yeah, everything else is here so).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, they seem more local state - I moved them down to be clearer.

@sebergseberg added the 09 - Backport-CandidatePRs tagged should be backported labelAug 14, 2025
@seberg
Copy link
Member

Thanks@MaanasArora, let's put this in.

This has been around forever, but I can't really see that not including an empty metadatadict in such a niche use-case can break anything, so I think we could backport.

@sebergseberg merged commit87e208c intonumpy:mainAug 14, 2025
77 checks passed
charris pushed a commit to charris/numpy that referenced this pull requestAug 14, 2025
* BUG: fix metadata not roundtripping for datetime pickles* STYLE: Remove unnecessary newline* REF: Simplify metadata handling in arraydescr_setstate function* TST: add test to ensure datetime dtype metadata round-trips on pickling* REF: clearer operation order* TST: add new regression test (numpygh-29555)* BUG: don't steal reference to Py_None* REF: move metadata variable declarations below for clarity
@charrischarris removed the 09 - Backport-CandidatePRs tagged should be backported labelAug 14, 2025
charris added a commit that referenced this pull requestAug 14, 2025
BUG: Fix metadata not roundtripping when pickling datetime (#29555)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@sebergsebergseberg left review comments

@tylerjereddytylerjereddytylerjereddy left review comments

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

BUG: Pickling/unpickling datetime64 adds dtype metadata

4 participants

@MaanasArora@seberg@tylerjereddy@charris

[8]ページ先頭

©2009-2025 Movatter.jp