[BUG]: Integer and string properties reject NumPy scalars
维护者通常 3 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 70/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
调研方向
首先阅读 IntegerValidator 和 StringValidator;issue 指出它们会拒绝 NumPy 标量。将它们的检查与 NumberValidator 的检查进行比较。重现 name、text、nticks 和 nbinsx 的示例,然后查找覆盖 Python 整数和数字的 validator 测试。当 issue 中描述的 NumPy 值在这些属性中被接受,且现有验证行为仍有测试覆盖时,任务即告完成。
由索引模型根据 Issue 内容生成。
描述
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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
plotly/plotly.py 的其他 Issue
-
to_typed_array_spec encodes bdata in host byte order; plotly.js always decodes it as little-endian可能已有人在做 @Vikram12301 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 3 天内回复
-
[BUG]: NaT inside a datetime64 array serializes as the string "NaT" instead of null可能已有人在做 @senanurcetin 于 3 天前认领。 未关闭bug P3 size: 1
难度 2/5 1-3 小时 新手友好度 82/100
plotly/plotly.py#5829 · 3 条评论 ·
维护者通常 3 天内回复
-
[BUG]: Single-color requests raise ZeroDivisionError in palette helpers可能已有人在做 @MokiMeow 于 13 天前认领。 未关闭bug P3 size: 1
难度 2/5 1-3 小时 新手友好度 82/100
plotly/plotly.py#5805 · 1 条评论 ·
维护者通常 3 天内回复
-
[BUG]: Unnecessary `UserWarning` when using `fig.write_image()` with `kaleido.start_sync_server()`可能已有人在做 @jayzhou2309 于 21 天前认领。 未关闭bug P3 size: 1
难度 2/5 1-3 小时 新手友好度 74/100
plotly/plotly.py#5786 · 1 条评论 ·
维护者通常 3 天内回复
-
P3 size: 1 task
难度 2/5 1-3 小时 新手友好度 65/100
plotly/plotly.py#5769 · 1 个 reaction ·
维护者通常 3 天内回复
相似的 Issue
-
bug
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 84/100
sergey-miryanov/gcmon#230 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
Azure-Samples/azure-search-openai-demo#3249 ·
维护者通常 1 天内回复
-
[BUG] Failed archive extraction deletes the dataset cache可能已有人在做 @dajiaohuang 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
alibaba/GraphScope#4674 ·