Skip to content

[ENH]: Typing: broaden acceptable floats #29332

@stefanv

Description

@stefanv

Problem

From plot_bar.py in the SP lecture notes, we have:

X = np.arange(n)
rng = np.random.default_rng()
Y1 = (1 - X / float(n)) * rng.uniform(0.5, 1.0, n)

for x, y in zip(X, Y1):
    plt.text(x, y + 0.05, f"{y:.2f}", ha="center", va="bottom")

Mypy reports typing errors:

intro/matplotlib/examples/plot_bar.py:22: error: Argument 1 to "text" has incompatible type "signedinteger[Any]"; expected "float"  [arg-type]
intro/matplotlib/examples/plot_bar.py:22: error: Argument 2 to "text" has incompatible type "floating[Any] | float64"; expected "float"  [arg-type]
intro/matplotlib/examples/plot_bar.py:25: error: Argument 1 to "text" has incompatible type "signedinteger[Any]"; expected "float"  [arg-type]
intro/matplotlib/examples/plot_bar.py:25: error: Argument 2 to "text" has incompatible type "floating[Any] | float64"; expected "float"  [arg-type]

Proposed solution

Could we broaden the floating point & integer types accepted?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy