Skip to content

DEP: Deprecate numpy.fix in favor of numpy.trunc - #30644

Merged
jorenham merged 8 commits into
numpy:mainfrom
skyvanguard:deprecate-np-fix
Jan 13, 2026
Merged

jorenham merged 8 commits into
numpy:mainfrom
skyvanguard:deprecate-np-fix

Conversation

@skyvanguard

Copy link
Copy Markdown

Summary

Deprecate numpy.fix as it provides identical functionality to numpy.trunc but is slower and is not part of the Array API standard.

Motivation

As noted in #30096:

  • numpy.fix and numpy.trunc produce identical results
  • numpy.trunc is ~2.5x faster than numpy.fix
  • The Array API standard defines trunc but not fix
  • The name trunc is clearer and more standard

Changes

  • Add DeprecationWarning to numpy.fix()
  • Update docstring with .. deprecated:: directive
  • Add tests to verify deprecation warning is emitted
  • Update existing tests to suppress deprecation warnings during functional tests
  • Add release note about deprecation

Performance comparison

In [1]: arr = np.random.random(1_000_000)*1000

In [2]: %timeit np.trunc(arr)
426 μs ± 15.1 μs per loop

In [3]: %timeit np.fix(arr)
1.06 ms ± 3.34 μs per loop

In [4]: np.all(np.trunc(arr) == np.fix(arr))
Out[4]: np.True_

Closes #30096

Deprecate `numpy.fix` as it provides identical functionality to
`numpy.trunc` but is slower and is not part of the Array API standard.

- Add DeprecationWarning to numpy.fix()
- Update docstring with .. deprecated:: directive
- Add tests to verify deprecation warning is emitted
- Update existing tests to suppress deprecation warnings
- Add release note about deprecation

Closes #30096
@jorenham

This comment was marked as resolved.

Comment thread numpy/lib/tests/test_ufunclike.py
Comment thread numpy/lib/_ufunclike_impl.py Outdated
Comment thread numpy/lib/_ufunclike_impl.py Outdated
@skyvanguard

Copy link
Copy Markdown
Author

Done! Removed category=PendingDeprecationWarning from the stubs and updated the deprecation message to match the runtime warning.

@skyvanguard

Copy link
Copy Markdown
Author

Fixed! Updated to NumPy 2.5 and 2026. Thanks for catching that 😅

@skyvanguard

Copy link
Copy Markdown
Author

Updated tests to use @pytest.mark.filterwarnings instead of warnings.catch_warnings(). Thanks for the guidance!

Comment thread numpy/typing/tests/data/pass/ufunclike.py Outdated
Move the deprecation warning filter from the test data file to the
actual test function. This ensures the filter follows NumPy testing
conventions and doesn't use warnings.filterwarnings in a non-test file.
@jorenham jorenham added this to the 2.5.0 Release milestone Jan 13, 2026
@jorenham
jorenham merged commit 60057c0 into numpy:main Jan 13, 2026
77 checks passed
@jorenham

Copy link
Copy Markdown
Member

Thanks @skyvanguard

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.

DEP: Deprecate np.fix

2 participants