FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

dtype.__repr__: prefer __name__ for user-defined types. by jakevdp · Pull Request #28250 · numpy/numpy · GitHub

/ numpy Public

dtype.__repr__: prefer __name__ for user-defined types. - #28250

Merged
charris merged 5 commits into
numpy:mainfrom
jakevdp:dtype-repr
Jan 31, 2025
Merged

charris merged 5 commits into
numpy:mainfrom
jakevdp:dtype-repr

Conversation

jakevdp commented Jan 29, 2025

Copy link
Copy Markdown
Contributor

The current approach can result in a misleading repr() for user-defined dtypes. For example, a bfloat16 scalar type that inherits from np.number and sets dtype.kind='f' will be displayed as dtype('float16') rather than dtype(bfloat16). We can circumvent this by handling user-defined dtypes first.

charris commented Jan 29, 2025

Copy link
Copy Markdown
Member

Could use a release note, as it is a behavior change.

jakevdp commented Jan 29, 2025

Copy link
Copy Markdown
Contributor Author

Added a release note and a test. The test doesn't really cover the motivating issue here, as rational does not inherit from np.number, but it's better than nothing. It may be worth adding some sort of test-only custom float type to better cover this sort of issue, but I'll punt on that for now.

Copy link
Copy Markdown
Member

There’s also the scaled float test dtype using the new dtype system. I want to add numpy-user-dtypes as a test-only dependency to make it easier to test stuff like this.

Copy link
Copy Markdown
Member

The behavior change seems fine to me and reads like what the code intended beyond that no one expected someone to write a user dtype set up like bfloat16.

charris commented Jan 30, 2025

Copy link
Copy Markdown
Member

Close/reopen. The test failure looks unrelated, but I would like to know what is going on.

charris closed this Jan 30, 2025
charris reopened this Jan 30, 2025

charris commented Jan 30, 2025

Copy link
Copy Markdown
Member

@jakevdp Could you try rebasing on current master to see if that fixes the build failure on CircleCI?

The current approach can result in a misleading repr() for user-defined dtypes. For example, a bfloat16 scalar type that inherits from np.number and sets dtype.kind='f' will be displayed as dtype('float16'). We can circumvent this by handling user-defined dtypes first.

jakevdp commented Jan 30, 2025

Copy link
Copy Markdown
Contributor Author

rebased

charris commented Jan 30, 2025

Copy link
Copy Markdown
Member

@jakevdp Thanks, that fixed the build. There was still an undefined reference, which I have fixed.

charris merged commit 6bc9058 into numpy:main Jan 31, 2025

charris commented Jan 31, 2025

Copy link
Copy Markdown
Member

Thanks @jakevdp .

jakevdp deleted the dtype-repr branch January 31, 2025 01:21
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
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.

3 participants


Back | FazBrowse Home | New Git URL