change context manager for temporary auto-reverted `figure.layout`
オープン
まだ誰も着手していません。
feature
P3
- 主要言語
- Python
- スター
- 18.8k
- フォーク
- 2.8k
- 平均マージ
- 16時間 26分
- マージ済み PR(30日)
- 21
説明
Instead of
fig.layout.showlegend = False
fig.write_image('plot.pdf')
fig.layout.showlegend = True
it would be nice to write
from plotly.express import plotly_patch # or similar
with plotly_patch(fig.layout, showlegend=False):
fig.write_image('plot.pdf')
I tried
from unittest.mock import patch
with patch.dict(fig.layout, showlegend=False):
fig.write_image('plot.pdf')
which unfortunately doesn't correctly restore the previous value but tries to delete the patched keys which is undesired behavior and raises AttributeError to boot:
1906 """Unpatch the dict."""
1907 if self._original is not None:
-> 1908 self._unpatch_dict()
...
1934 keys = list(in_dict)
1935 for key in keys:
-> 1936 del in_dict[key]
AttributeError: __delitem__
Related
Found this forum post where such a context manager was welcomed.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
issue ではソースファイルもテストも指定されていません。まず figure layout の変更と復元の動作を見つけ、次に context manager が既存の値を保持し、fig.write_image('plot.pdf'); の後に復元する方法を調べてください。done には、layout のキーを削除せずに一時的な showlegend の変更を対象とするカバレッジを含める必要があります。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- data-visualization
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100