Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 15, 2025

The custom searchsorted function was implemented when Numba didn't support the side keyword argument for np.searchsorted. Numba now supports this feature, making the custom implementation redundant.

Changes

  • quantecon/util/array.py: Added deprecation warning using objmode() while keeping the JIT-compiled implementation for performance
  • quantecon/random/utilities.py: Replaced 3 internal uses with direct np.searchsorted calls
  • quantecon/markov/core.py: Replaced 3 internal uses with direct np.searchsorted calls
  • quantecon/util/tests/test_array.py: Added @pytest.mark.filterwarnings decorator to suppress warnings in main test and added separate test_warns() function to verify deprecation warning

Implementation Details

The deprecated searchsorted function:

  • Still uses JIT compilation for performance
  • Emits DeprecationWarning using objmode() context
  • Maintains backward compatibility
  • Will be removed in a future release

Migration

Users should replace:

from quantecon import searchsorted
result = searchsorted(a, v)

With:

import numpy as np
result = np.searchsorted(a, v, side='right')

The function remains exported for backward compatibility but will be removed in a future release.

Original prompt

This section details on the original issue you should resolve

<issue_title>RFC: Deprecate util.array.searchsorted</issue_title>
<issue_description>Deprecate searchsorted(a, v) in util/array.py and replace it with np.searchsorted(a, v, side='right').
(Numba was not supporting the side keyword argument when this function was implemented.)

  1. Replace any use of util.array.searchsorted with np.searchsorted(a, v, side='right').
    (⚡️ Speed up function draw by 390% #811 is such an example.)
  2. Rewrite searchsorted in util/array.py so that it simply returns np.searchsorted(a, v, side='right'), emitting DeprecationWarning.
    (Remove this function in some future release.)
  3. Rewrite the docstring of searchsorted in util/array.py accordingly.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: oyamad <7353083+oyamad@users.noreply.github.com>
Copilot AI changed the title [WIP] Deprecate util.array.searchsorted in favor of np.searchsorted Deprecate util.array.searchsorted in favor of np.searchsorted Nov 15, 2025
Copilot AI requested a review from oyamad November 15, 2025 09:31
Copilot finished work on behalf of oyamad November 15, 2025 09:31
Copy link
Member

@oyamad oyamad left a comment

Choose a reason for hiding this comment

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

@copilot (Read the comment #813 (comment))

  • Abandon all your changes in array.py and test_array.py, and incorporate (or just merge) those in ab0fa74

…ation

- Reverted array.py and test_array.py to use the implementation from commit ab0fa74
- This version keeps the JIT-compiled searchsorted but emits deprecation warning
- Fixed indentation in markov/core.py line 666 as suggested in code review
- Removed unused numpy import from array.py

Co-authored-by: oyamad <7353083+oyamad@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 15, 2025

@copilot (Read the comment #813 (comment))

  • Abandon all your changes in array.py and test_array.py, and incorporate (or just merge) ...

Incorporated the changes from commit ab0fa74. The implementation now keeps the JIT-compiled searchsorted while emitting a deprecation warning via objmode(). Commit: f4477ea

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/QuantEcon/QuantEcon.py/issues/813/comments
    • Triggering command: curl -s REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from oyamad November 15, 2025 09:45
Copilot finished work on behalf of oyamad November 15, 2025 09:45
@coveralls
Copy link

Coverage Status

coverage: 92.586% (+0.009%) from 92.577%
when pulling ec62a7c on copilot/deprecate-util-array-searchsorted
into 83d3c6c on main.

@oyamad oyamad marked this pull request as ready for review November 15, 2025 11:50
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.

RFC: Deprecate util.array.searchsorted

3 participants