add "Non-leaves rows are not permitted in the dataframe" with sunburst diagrams
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 18.8k
- フォーク
- 2.8k
- 平均マージ
- 16時間 26分
- マージ済み PR(30日)
- 21
説明
It is sometimes useful to have non-leaf data in a Sunburst diagram. However, there is no way to tell Plotly Express to ignore or accept non-leaves.
Minimum viable example:
import pandas as pd
import plotly.express as px
lst = [['Alice', "Bob"], ['Alice', "Bob", "Carrie"], ["Alice", "Bob", "Chuck"]]
df = pd.DataFrame(lst)
fig = px.sunburst(df, path=df.columns)
Gives the error:
ValueError: ('Non-leaves rows are not permitted in the dataframe \n', 0 Alice
1 Bob
2
Name: 0, dtype: object, 'is not a leaf.')
This can be fixed by commenting out part of plotly/express/_core.py
def _check_dataframe_all_leaves(df):
df_sorted = df.sort_values(by=list(df.columns))
null_mask = df_sorted.isnull()
df_sorted = df_sorted.astype(str)
null_indices = np.nonzero(null_mask.any(axis=1).values)[0]
for null_row_index in null_indices:
row = null_mask.iloc[null_row_index]
i = np.nonzero(row.values)[0][0]
if not row[i:].all():
raise ValueError(
"None entries cannot have not-None children",
df_sorted.iloc[null_row_index],
)
df_sorted[null_mask] = ""
row_strings = list(df_sorted.apply(lambda x: "".join(x), axis=1))
#for i, row in enumerate(row_strings[:-1]):
#if row_strings[i + 1] in row and (i + 1) in null_indices:
#raise ValueError(
# "Non-leaves rows are not permitted in the dataframe \n",
# df_sorted.iloc[i + 1],
# "is not a leaf.",
#)
It would be great if px.sunburst could have an option to disable these checks, or to skip over any row which is not a leaf.
How can I propose this as an option?
Thanks!
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
plotly/express/_core.py の _check_dataframe_all_leaves から始め、提供されている pandas と px.sunburst の例で問題を再現します。px.sunburst が葉でない行を受け入れるかスキップするためのオプションを公開する方法を調査し、そのオプションを有効にしたときに例で現在の非リーフ行エラーが発生しなくなることを完了条件とします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- data-visualization
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100