Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[BUG]: Integer and string properties reject NumPy scalars

Aperta Adatta ai principianti
#5,827 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@RaphaelFakhri ci sta già lavorando.

Dal 19/10/2026.

  • #5828 di @RaphaelFakhri — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
70/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
numpy, pandas, python

Direzione di ricerca

Inizia leggendo IntegerValidator e StringValidator, che secondo l’issue rifiutano gli scalari NumPy, e confronta i loro controlli con quelli di NumberValidator. Riproduci gli esempi per name, text, nticks e nbinsx, poi cerca i test dei validatori che coprono gli interi e i numeri Python. Il lavoro è concluso quando i valori NumPy descritti nell’issue sono accettati in queste proprietà e il comportamento di convalida esistente continua a essere coperto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug P3 size: 1
Description

Graph object properties validated as integers (such as layout.xaxis.nticks, histogram.nbinsx and layout.updatemenus[].active) reject NumPy integer scalars, and properties validated as non-strict strings (such as name and text) reject NumPy integer and float32 scalars. Python int and float values of the same number are accepted, and number properties such as marker.size already accept NumPy scalars.

This breaks a common pattern: building one trace per value of a DataFrame column with Series.unique(), which returns NumPy scalars.

Expected: NumPy integers are accepted wherever a Python int is, and NumPy numbers are converted to strings the same way Python numbers are.

Steps to reproduce
import numpy as np
import pandas as pd
import plotly.graph_objects as go

df = pd.DataFrame({"year": [2020, 2021], "v": [1, 2]})

for label, call in [
    ("name", lambda: go.Scatter(name=df.year.unique()[0])),
    ("text", lambda: go.Scatter(text=np.float32(1.5))),
    ("nticks", lambda: go.Layout(xaxis_nticks=np.int64(5))),
    ("nbinsx", lambda: go.Histogram(nbinsx=np.int32(10))),
]:
    try:
        call()
        print(label, "ok")
    except ValueError as error:
        print(label, str(error).splitlines()[1].strip())

Actual:

name Invalid value of type 'numpy.int64' received for the 'name' property of scatter
text Invalid value of type 'numpy.float32' received for the 'text' property of scatter
nticks Invalid value of type 'numpy.int64' received for the 'nticks' property of layout.xaxis
nbinsx Invalid value of type 'numpy.int32' received for the 'nbinsx' property of histogram

Expected:

name ok
text ok
nticks ok
nbinsx ok
Notes

IntegerValidator checks isinstance(v, int) and StringValidator checks isinstance(v, (int, float)). NumPy integer types are not subclasses of int, so they fail both checks, while NumberValidator checks numbers.Number and accepts them. The error message for string properties says "A number that will be converted to a string", which a NumPy number is.

Reproduced with plotly 7.1.0 and current main (38374acd), NumPy 2.x, Python 3.12.

Lingua principale
Python
Stelle
18.9k
Fork
2.9k
Merge medio
2g 7h
PR unite (30g)
12

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di plotly/plotly.py

Tutte le issue di plotly/plotly.py

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.