Skip to content

DEP: Give a visible warning when align= to dtype is a non-bool#29301

Merged
mattip merged 2 commits intonumpy:mainfrom
seberg:dtype-align
Jul 2, 2025
Merged

DEP: Give a visible warning when align= to dtype is a non-bool#29301
mattip merged 2 commits intonumpy:mainfrom
seberg:dtype-align

Conversation

@seberg
Copy link
Copy Markdown
Member

@seberg seberg commented Jul 1, 2025

This seems generally confusing. I would like to make it keyword only, but this already gives a warning when loading very old pickles, meaning I am not quite sure we should change away from a warning quickly.

We should fix things around pickling and start pickling in a way that makes it easier to move to keyword only arguments. (I suppose one could detect the case of np.dtype(obj, False, True) and assume it is via unpickling, but...

I am assuming that it is OK to (eventually) break unpickling these 10+ year old files, but I am not in a rush to actually do so and go through with the deprecation.

Closes gh-8158


The one way to really avoid all of those warnings for ancient pickles, might be to just explicitly accept np.dtype(obj, 0, 1) (and maybe the current np.dtype(obj, False, True)) exactly, basically just hoping that such a call came from pickle.

That is a whim, but users are unlikely to pass those exact parameters in practice probably...

This seems generally confusing. I would like to make it keyword only,
but this already gives a warning when loading _very_ old pickles, meaning
I am not quite sure we should change away from a warning quickly.

We should fix things around pickling and start pickling in a way that
makes it easier to move to keyword only arguments.  (I suppose one could
detect the case of `np.dtype(obj, False, True)` and assume it is via
unpickling, but...

I am assuming that it is OK to (eventually) break unpickling these 10+ year
old files, but I am not in a rush to actually do so and go through with
the deprecation.

Signed-off-by: Sebastian Berg <[email protected]>
Copy link
Copy Markdown
Member

@mattip mattip left a comment

Choose a reason for hiding this comment

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

LGTM, One tiny typo.

@mattip mattip merged commit b934a81 into numpy:main Jul 2, 2025
76 checks passed
@mattip
Copy link
Copy Markdown
Member

mattip commented Jul 2, 2025

Thanks @seberg

@gdementen
Copy link
Copy Markdown
Contributor

FWIW, I just hit this after upgrading my numpy version to 2.4 when loading old HDF5 files created via Pandas (which used PyTables). This is extremely annoying because we have a lot of data archived in those files and I never realized until now that H5 (created via pytables) was not a good archival format and could have forward compatibility problems 😞.

I am not saying the deprecation should be reverted or anything... I understand the motivation of the change... But I am really not enthusiastic at the idea of rewriting all those old files 😭.

@seberg
Copy link
Copy Markdown
Member Author

seberg commented Mar 26, 2026

It would be nice to figure out a way to deprecate it but avoid the deprecation with pickles. The only path I can think of right now is to use copyreg. But maybe that is fine?!
(The other old idea was to catch the precise case where this is used in old pickle files, which makes it a weird little part that isn't deprecated but otherwise it is).

(I guess HDF5 is just pickle for object arrays? Not sure I know why hdf5 files would have pickles of dtypes... or maybe as some metadata...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dtype ctor allows "align" kwargs even when unapplicable

3 participants