Bug Report:
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- pandas, python
- Lĩnh vực
- data-visualization
Hướng nghiên cứu
Bắt đầu trong _utils.py tại _calculate_atr và theo dõi cách các đầu vào highs, lows và closes của nó được cung cấp cho các biểu đồ PNF và Renko. Tái hiện cả hai trường hợp biểu đồ trong báo cáo, sau đó xác minh rằng cảnh báo đã biến mất đối với PNF và đường dẫn Renko không còn phát sinh lỗi thuộc tính ndarray đã được báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 4.4k
- Fork
- 678
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của matplotlib/mplfinance
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
matplotlib/mplfinance#672 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
matplotlib/mplfinance#700 ·
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
matplotlib/mplfinance#695 ·
-
question
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
matplotlib/mplfinance#691 · 1 bình luận ·
-
question
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
matplotlib/mplfinance#690 · 5 bình luận ·
Tất cả issue của matplotlib/mplfinance
Issue tương tự
-
[Bug] reef-hermes tells me to resume with hermes --resume, which does not work from my shell Đang mởarea: harness bug status: needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Human-Agent-Society/reef#625 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
learningequality/kolibri#15351 · 2 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Name consistency Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
eellak/triplestore#65 · 1 bình luận ·