Skip to content

ENH: float.from_number implementation #29077

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
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

ganesh-k13
Copy link
Member

@ganesh-k13 ganesh-k13 commented May 28, 2025

Changes

Add float.from_number for floating types

Testing

In [3]: np.float16.from_number(7), type(np.float16.from_number(7))
Out[3]: (np.float16(7.0), numpy.float16)

In [4]: np.float16.from_number(100000000000000000)
Out[4]: np.float16(inf)

In [5]: np.float16.from_number('a')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
TypeError: must be real number, not str

Related

part of #13375

Todo

Float:

  • release notes
  • UT
  • typing
  • docs

Complex

  • release notes
  • UT
  • typing
  • docs

@ganesh-k13 ganesh-k13 self-assigned this May 28, 2025
@ganesh-k13 ganesh-k13 added 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes 62 - Python API Changes or additions to the Python API. Mailing list should usually be notified. labels May 28, 2025
@ganesh-k13 ganesh-k13 requested a review from jorenham June 9, 2025 08:52
@ganesh-k13 ganesh-k13 marked this pull request as ready for review June 9, 2025 09:16
@ganesh-k13 ganesh-k13 removed the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label Jun 9, 2025
Copy link
Member

@jorenham jorenham left a comment

Choose a reason for hiding this comment

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

Since there's also a complex.from_number in Python π, maybe it would make sense to also include complexfloating, e.g. by adding np.inexact.from_number?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
01 - Enhancement 62 - Python API Changes or additions to the Python API. Mailing list should usually be notified.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants