`to_json` does not handle color as `np.nan` properly
オープン
まだ誰も着手していません。
bug
P3
- 主要言語
- Python
- スター
- 18.8k
- フォーク
- 2.8k
- 平均マージ
- 16時間 26分
- マージ済み PR(30日)
- 21
説明
When creating a scatter plot with colors including np.nan the figure shows fine.
import json
import numpy as np
import plotly.graph_objects as go
go.Figure(go.Scatter(x=[0, 0], y=[0, 1], marker={"color": [0, np.nan]}))
However, if I convert the figure to JSON and load it back, there will be an error.
fig = go.Figure(go.Scatter(x=[0, 0], y=[0, 1], marker={"color": [0, np.nan]}))
go.Figure(**json.loads(fig.to_json()))
Error message:
ValueError:
Invalid element(s) received for the 'color' property of scatter.marker
Invalid elements include: [None]
The 'color' property is a color and may be specified as:
- A hex string (e.g. '#ff0000')
- An rgb/rgba string (e.g. 'rgb(255,0,0)')
- An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
- An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
- A named CSS color:
aliceblue, antiquewhite, aqua, aquamarine, azure,
beige, bisque, black, blanchedalmond, blue,
blueviolet, brown, burlywood, cadetblue,
chartreuse, chocolate, coral, cornflowerblue,
cornsilk, crimson, cyan, darkblue, darkcyan,
darkgoldenrod, darkgray, darkgrey, darkgreen,
darkkhaki, darkmagenta, darkolivegreen, darkorange,
darkorchid, darkred, darksalmon, darkseagreen,
darkslateblue, darkslategray, darkslategrey,
darkturquoise, darkviolet, deeppink, deepskyblue,
dimgray, dimgrey, dodgerblue, firebrick,
floralwhite, forestgreen, fuchsia, gainsboro,
ghostwhite, gold, goldenrod, gray, grey, green,
greenyellow, honeydew, hotpink, indianred, indigo,
ivory, khaki, lavender, lavenderblush, lawngreen,
lemonchiffon, lightblue, lightcoral, lightcyan,
lightgoldenrodyellow, lightgray, lightgrey,
lightgreen, lightpink, lightsalmon, lightseagreen,
lightskyblue, lightslategray, lightslategrey,
lightsteelblue, lightyellow, lime, limegreen,
linen, magenta, maroon, mediumaquamarine,
mediumblue, mediumorchid, mediumpurple,
mediumseagreen, mediumslateblue, mediumspringgreen,
mediumturquoise, mediumvioletred, midnightblue,
mintcream, mistyrose, moccasin, navajowhite, navy,
oldlace, olive, olivedrab, orange, orangered,
orchid, palegoldenrod, palegreen, paleturquoise,
palevioletred, papayawhip, peachpuff, peru, pink,
plum, powderblue, purple, red, rosybrown,
royalblue, rebeccapurple, saddlebrown, salmon,
sandybrown, seagreen, seashell, sienna, silver,
skyblue, slateblue, slategray, slategrey, snow,
springgreen, steelblue, tan, teal, thistle, tomato,
turquoise, violet, wheat, white, whitesmoke,
yellow, yellowgreen
- A number that will be interpreted as a color
according to scatter.marker.colorscale
- A list or array of any of the above
Interestingly, the to_plotly_json method works fine:
fig = go.Figure(go.Scatter(x=[0, 0], y=[0, 1], marker={"color": [0, np.nan]}))
go.Figure(**json.loads(json.dumps(fig.to_plotly_json())))
Questions: Is this the expected behavior for the to_json method, and why it behaves differently from the to_plotly_json method?
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
レポートにある Figure.to_json、Figure.to_plotly_json、および scatter マーカーの色の例を使って問題を再現してください。これらのシリアライゼーションのエントリーポイントを比較して、round-trip 中に np.nan がどのように表現されるかを確認し、そのうえで意図した一貫した動作を対象とする回帰テストを追加してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- numpy, python
- 領域
- data-visualization
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100