Skip to content

Conversation

@wagner-austin
Copy link
Contributor

@wagner-austin wagner-austin commented Jan 18, 2026

Mypy Error (before fix)

python-package/lightgbm/plotting.py:143: error: Argument 2 to "text" of "Axes" has incompatible type "signedinteger[_32Bit | _64Bit]"; expected "float"  [arg-type]

Related Issue

Contributes to #3867

Description

The y-coordinate passed to matplotlib's ax.text() in plot_importance() was a numpy signedinteger from iterating over np.arange(), but matplotlib's type stubs expect a Python float.

This cast follows the existing pattern in engine.py where float() is used to convert numpy values (e.g., float(np.mean(v)) at line 624).

Test Plan

  • Ran pre-commit run mypy --files python-package/lightgbm/plotting.py - passed
  • Verified mypy no longer reports error for line 143
  • Ran pytest tests/python_package_test/test_plotting.py - 13 passed, 1 skipped (pre-existing skip unrelated to this change)

…xt call

The y-coordinate passed to matplotlib's ax.text() was a numpy signedinteger from
np.arange(), but matplotlib's type stubs expect a Python float. This cast follows
the existing pattern in engine.py where float() is used to convert numpy values.
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.

Looks good to me, and confirmed this results in 0 remaining mypy errors in plotting.py: https://github.com/microsoft/LightGBM/actions/runs/21103515583/job/60691173605#step:3:891

Thanks!

@jameslamb
Copy link
Collaborator

I've changed the description to:

Contributes to #3867

"fixes" should only be used if the issue could be closed after this PR is merged, which isn't true here (there are still 6 more mypy errors to resolve). See the previous note I gave you on this here: #7116 (comment)

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.

2 participants