Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[BUG]: Integer and string properties reject NumPy scalars

未关闭 适合新手
#5,827 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

@RaphaelFakhri 已经在做这个了。

开始于 2026年10月19日。

  • #5828 来自 @RaphaelFakhri —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
70/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
numpy, pandas, python

调研方向

首先阅读 IntegerValidator 和 StringValidator;issue 指出它们会拒绝 NumPy 标量。将它们的检查与 NumberValidator 的检查进行比较。重现 name、text、nticks 和 nbinsx 的示例,然后查找覆盖 Python 整数和数字的 validator 测试。当 issue 中描述的 NumPy 值在这些属性中被接受,且现有验证行为仍有测试覆盖时,任务即告完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
18.9k
派生
2.9k
平均合并
5 天 1 小时
30 天内合并 PR
14

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

plotly/plotly.py 的其他 Issue

查看 plotly/plotly.py 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。