Skip to content

DOC: document type promotion with Python types #27404

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 4 commits into from
May 10, 2025

Conversation

matthiasdiener
Copy link
Contributor

cc @seberg.

Closes #27325.

Comment on lines +217 to +218
The reason for this behavior is that NumPy converts ``int`` to its default
integer type, and uses that type for promotion:
Copy link
Contributor Author

@matthiasdiener matthiasdiener Sep 16, 2024

Choose a reason for hiding this comment

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

Side note: I could not find good documentation on default integer/float/complex type besides the somewhat confusing https://numpy.org/devdocs/numpy_2_0_migration_guide.html#windows-default-integer; perhaps we could add a subsection somewhere in this file?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I was out while this happened. But would also value someone else's input here.

To me, this is a detail about result_type. And I feel that it should be mentioned there mainly?
(It is also something that we probably should consider changing there!)

Copy link
Member

Choose a reason for hiding this comment

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

The default types are documented in the list of types, I think. But, I suppose we could move the footnote about it up and just state the fact that the default is int64 on 64bit systems (which are most systems, so we use that).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I added a reference to the promotion list in 904a6f5. I also reworded the footnote slightly.

To me, this is a detail about result_type. And I feel that it should be mentioned there mainly?
(It is also something that we probably should consider changing there!)

Do you mean, should this whole subsection be moved to the result_type doc, or just the default integer discussion?

Copy link
Member

Choose a reason for hiding this comment

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

I was wondering about this whole addition. The reason is that I don't think we mention the syntax of result_type to allow dtypes at all (which is the crux, int here would ideally not be a dtype instance, but an abstract DType class/type. But result_tyee uses np.dtype(int) which does a silly guess at the default).

So I am wondering if adding it here just adds another layer of complexity that is mainly needed with result_type. OTOH, explaining result_type in more detail here could make sense...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. Just as an additional wrinkle, promote_types also accepts int...

@charris charris merged commit 022a306 into numpy:main May 10, 2025
65 of 67 checks passed
@charris
Copy link
Member

charris commented May 10, 2025

Thanks @matthiasdiener .

@matthiasdiener matthiasdiener deleted the array-promo-doc-python-types branch May 10, 2025 21:10
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.

DOC: Surprising result of type promotion with Python's builtin type classes
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy