Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

[BUG]: Integer and string properties reject NumPy scalars

Aberta Para iniciantes
#5,827 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 2 dias

@RaphaelFakhri já está trabalhando nisso.

Desde 19/10/2026.

  • #5828 de @RaphaelFakhri — aberto

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
70/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
numpy, pandas, python

Direção de pesquisa

Comece lendo IntegerValidator e StringValidator, que, segundo a issue, rejeitam escalares do NumPy, e compare suas verificações com as de NumberValidator. Reproduza os exemplos para name, text, nticks e nbinsx e, em seguida, procure testes dos validadores que cubram números inteiros e números do Python. O trabalho estará concluído quando os valores do NumPy descritos na issue forem aceitos nessas propriedades e o comportamento de validação existente continuar coberto.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Python
Estrelas
18.9k
Forks
2.9k
Merge médio
2d 7h
PRs com merge (30d)
12

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de plotly/plotly.py

Todas as issues de plotly/plotly.py

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.