Bug Report:
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- pandas, python
調査の方向性
_utils.py の _calculate_atr から始め、PNF チャートと Renko チャートに対して、その highs、lows、closes の入力がどのように渡されているかを追跡します。レポートにある両方のチャートケースを再現し、その後、PNF で警告がなくなっていることと、Renko のパスで報告された ndarray 属性エラーが発生しなくなっていることを確認します。
索引モデルが issue の本文から書いたものです。
説明
Bug when using box_size = 'atr' in pnf charts in mplfinance : FutureWarning: Series.getitem treating keys as positions is deprecated
OS Win 11 Pro 24H2 Desktop
IDE Visual Studio Code 1.96.2
Python 3.12.8
mplfinance 0.12.10b0
When using the 'atr' box_size parameter in creating pnf charts in mplfinance the _utils.py script throws this warning
\mplfinance_utils.py:129: FutureWarning: Series.getitem treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use ser.iloc[pos] high = highs[i]
\mplfinance_utils.py:130: FutureWarning: Series.getitem treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use ser.iloc[pos] low = lows[i]
_utils.py:131: FutureWarning: Series.getitem treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use ser.iloc[pos] close_prev = closes[i-1]
This is the responsible function:
def _calculate_atr(atr_length, highs, lows, closes):
"""Calculate the average true range
atr_length : time period to calculate over
all_highs : list of highs
all_lows : list of lows
all_closes : list of closes
"""
if atr_length < 1:
raise ValueError("Specified atr_length may not be less than 1")
elif atr_length >= len(closes):
raise ValueError("Specified atr_length is larger than the length of the dataset: " + str(len(closes)))
atr = 0
for i in range(len(highs)-atr_length, len(highs)):
high = highs[i]
low = lows[i]
close_prev = closes[i-1]
tr = max(abs(high-low), abs(high-close_prev), abs(low-close_prev))
atr += tr
return atr/atr_length
This warning is suppressed when you modify the code like so
high = highs.iloc[i]
low = lows.iloc[i]
close_prev = closes.iloc[i-1]
This however creates a new problem if you subsequently run a Renko chart, you get this error
LocalCache\local-packages\Python312\site-pa
high = highs.iloc[i]
^^^^^^^^^^
AttributeError: 'numpy.ndarray' object has no attribute 'iloc'
To fix this I created a small helper function
def safe_indexing(data, index):
if isinstance(data, pd.Series):
return data.iloc[index]
else:
return data[index]
and placed it in _utils.py
and updated _utils.py
high = highs[i]
low = lows[i]
close_prev = closes[i-1]
to
high = safe_indexing(highs, i)
low = safe_indexing(lows, i)
close_prev = safe_indexing(closes, i-1)
Now both charts render with no messages
- 主要言語
- Python
- スター
- 4.4k
- フォーク
- 678
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
matplotlib/mplfinance のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
matplotlib/mplfinance#672 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
matplotlib/mplfinance#700 ·
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
matplotlib/mplfinance#695 ·
-
question
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
matplotlib/mplfinance#691 · コメント 1 件 ·
-
question
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
matplotlib/mplfinance#690 · コメント 5 件 ·
matplotlib/mplfinance の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
stephrobert/dsoxlab#238 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
sublimehq/package_control#1780 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
nwg-piotr/nwg-displays#145 ·