Skip to content

Conversation

@wagner-austin
Copy link
Contributor

@wagner-austin wagner-austin commented Dec 30, 2025

Summary

Change np.arange calls from keyword arguments to positional arguments in _InnerPredictor to fix mypy call-overload errors. Numpy's type stubs have overloads for positional args but not for (start=int, stop=int, step=int) keyword args.

Mypy Error (before fix)

python-package/lightgbm/basic.py:1320: error: No overload variant of "arange" matches argument types "int", "Any", "int"  [call-overload]
python-package/lightgbm/basic.py:1536: error: No overload variant of "arange" matches argument types "int", "int", "int"  [call-overload]

Related Issue

Fixes: #3867

Test Plan

  • Ran pre-commit run mypy --files python-package/lightgbm/basic.py
  • Verified mypy no longer reports call-overload errors for lines 1320 and 1536

The numpy stubs define arange with positional-only parameters so keyword
arguments start=, stop=, step= do not match any overload. Changed to
positional arguments np.arange(_MAX_INT32, nrow, _MAX_INT32) which matches
the numpy stubs correctly and resolves the mypy call-overload errors.
Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

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

Oh wow, thank you for this! I'm sad to see us lose keyword arguments here as they do add a bit of clarity, but it really does seem that's what numpy expects.

From help(np.arange) on numpy==2.2.5:

arange(...)
    arange([start,] stop[, step,], dtype=None, *, device=None, like=None)

    Return evenly spaced values within a given interval.

    ``arange`` can be called with a varying number of positional arguments:

    * ``arange(stop)``: Values are generated within the half-open interval
      ``[0, stop)`` (in other words, the interval including `start` but
      excluding `stop`).
    * ``arange(start, stop)``: Values are generated within the half-open
      interval ``[start, stop)``.
    * ``arange(start, stop, step)`` Values are generated within the half-open
      interval ``[start, stop)``, with spacing between values given by
      ``step``

And it even looks like these stubs were recently updated to now call that first argument start_or_stop: numpy/numpy#30147

It also looks like these were the only uses in lightgbm where np.arange() is called with keyword arguments. All others use positional arguments:

git grep -E 'np\.arange'

Thanks!

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.

[ci] warnings from mypy

2 participants