Sorted categories (Pandas `Categorical` series) aren't sorted in chart
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 18.8k
- フォーク
- 2.8k
- 平均マージ
- 16時間 26分
- マージ済み PR(30日)
- 21
説明
I am plotting a chart with a pd.Categorical series on the x-axis. The category has a sort defined.
Expected behaviour: the axis is sorted as per the underlying category definition
Actual behaviour: the axis is sorted by the order of the data
df = pd.DataFrame(
dict(
Cost=[10, 20, 15, 2, 9],
Rating=pd.Categorical(
values=["High", "Low", "Medium", "Low", "Medium"],
categories=["Low", "Medium", "High"],
ordered=True,
),
)
)
fig = px.scatter(df, x="Rating", y="Cost")
This fix would be fairly simple, I think, something like this, where series is whatever's being rendered to the xaxis (or y, or legend, etc)
if isinstance(series.dtype, pd.CategoricalDtype) and series.cat.ordered:
fig.update_xaxes(
categoryorder="array",
categoryarray=series.cat.categories,
)
Plotly version: 5.9.0.
I've noticed a number of bugs relating to pd.Categorical and pd.PeriodIndex, are there plans for better Pandas support, or is that not an area of focus?
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された pandas DataFrame と px.scatter(df, x="Rating", y="Cost") のエントリーポイントで問題を再現し、その後、カテゴリカルな軸の値がどのように処理されるかを追跡します。順序付きカテゴリが軸の順序を決定することを確認し、リグレッションカバレッジを追加します。完了とは、チャートがデータの順序ではなく Low、Medium、High の順に従うことです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- pandas, python
- 領域
- data-visualization
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100