-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: __trunc__
for floating and integer types
#28949
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
ganesh-k13
wants to merge
17
commits into
numpy:main
Choose a base branch
from
ganesh-k13:trunc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+93
−1
Open
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1b9f6fa
ENH: Added float.__trunc__
ganesh-k13 e7634c2
DOC: Added documentation for `float.__trunc__`
ganesh-k13 79f102d
BUG: Cast halfs to prevent overflow
ganesh-k13 b442ec0
TST: Added TCs for `float.__trunc__`
ganesh-k13 4280f69
TYP: Typing for `float.__trunc__`
ganesh-k13 fa2a67a
MAINT: Refactor to use `gentype_int`
ganesh-k13 4c60023
TYP: Removed `trunc` ignore
ganesh-k13 89a0f9e
ENH: Added `int.__trunc__`
ganesh-k13 c091527
TST: Refined UT for Truncate
ganesh-k13 24e6e21
TST, BUG: Use `int` in float tests to avoid overflow
ganesh-k13 4bdc3ba
TYP: Moved `trunc` to `_RoundMixin`
ganesh-k13 bb11cf4
DOC: `__trunc__` for scalars (#27789)
ganesh-k13 2dcd189
DOC: Added version for `int.__trunc__`
ganesh-k13 7a46194
DOC: Remove `overload`
ganesh-k13 91e0961
DOC: Removed `versionadded` for `float64`
ganesh-k13 fea22cf
MAINT: Move `trunc` to `*type_methods[]`
ganesh-k13 426d3b2
DOC, MAINT: Fix docstring to use `format`
ganesh-k13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Add ``__trunc__`` method to NumPy scalar types | ||
============================================== | ||
|
||
NumPy scalar floating and integer types now implement the ``__trunc__`` special method, matching Python’s built-in numeric types. This enables direct use of :func:`math.trunc` and the ``__trunc__`` dunder method on NumPy scalars: | ||
|
||
Examples | ||
-------- | ||
|
||
.. code-block:: python | ||
|
||
>>> import numpy as np | ||
>>> import math | ||
>>> math.trunc(np.float16(np.pi)) | ||
3 | ||
>>> np.float16(-np.pi).__trunc__() | ||
-3 | ||
>>> np.int32(42).__trunc__() | ||
42 | ||
|
||
Attempting to truncate infinite or NaN values for floating point types will now raise the same errors as Python floats. | ||
|
||
.. versionadded:: 2.3 |
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
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
ganesh-k13 marked this conversation as resolved.
Show resolved
Hide resolved
|
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
jorenham marked this conversation as resolved.
Show resolved
Hide resolved
|
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.