Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[BUG]: Single-color requests raise ZeroDivisionError in palette helpers

オープン 初心者向け
#5,805 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@MokiMeow がすでに取り組んでいます。

2026年10月10日 から。

  • #5806 @MokiMeow による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python

調査の方向性

バグは plotly.colors ヘルパーの sample_colorscale と n_colors にあり、どちらも要求された個数から 1 を引いた値で除算しています。まず issue の再現スクリプトを実行し、個数が 1 の場合に ZeroDivisionError が発生することを確認してください。単一の色を要求したときに区間の開始点(low / lowcolor)の色が 1 つ返され、それが複数色の場合の最初のサンプルと一致し、色が 0 個の場合も空のリストを返し続けていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug P3 size: 1
Description

sample_colorscale and n_colors raise ZeroDivisionError when asked for one color. This breaks palettes sized to a dataset's group count when there is exactly one group. Both helpers divide by the requested count minus one.

Expected: one color from the start of the interval (low / lowcolor), consistent with their existing first sample.

Screenshots/Video

The API calls fail before a figure can be created; the output is shown below.

Steps to reproduce
from plotly.colors import n_colors, sample_colorscale

for label, call in [
    ("sample_colorscale", lambda: sample_colorscale("Viridis", 1)),
    ("n_colors", lambda: n_colors((0, 0, 0), (1, 1, 1), 1)),
]:
    try:
        print(label, call())
    except ZeroDivisionError as error:
        print(label, type(error).__name__, str(error))

Actual:

sample_colorscale ZeroDivisionError division by zero
n_colors ZeroDivisionError float division by zero

Expected:

sample_colorscale ['rgb(68, 1, 84)']
n_colors [(0.0, 0.0, 0.0)]
Notes

Reproduced with Plotly 7.1.0, current main 3f8a650930feadfdb651cd869ffe3e85fd093885, Python 3.12.10, Windows amd64. Zero-color requests already return empty lists.

主要言語
Python
スター
18.8k
フォーク
2.9k
平均マージ
3日 7時間
マージ済み PR(30日)
20

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

plotly/plotly.py のほかの issue

plotly/plotly.py の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。