Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bug Report: Errors occur for NaN columns. #672

Open
Labels
bugSomething isn't working
@z4m1

Description

issue case

When animating over a limited visual range, as in this example, the possibility arises that the signal columns are all NaN.

2024年05月26日.18-50-16.mp4

issue

mplfinance\plotting.py", line 1108, in _addplot_columns
ymhi = math.log(max(math.fabs(np.nanmax(yd)),1e-7),10)
This Numpy code generates an error.
"ValueError: zero-size array to reduction operation maximum which has no identity"

Error reproduction

import datetime
import numpy as np
import pandas as pd
import mplfinance as mpf
# ランダムなOHLCデータを生成する関数
def generate_sample_ohlc_data(n=10):
 # 現在の日付を取得
 base_date = datetime.datetime.now()
 # 日付のリストを生成
 dates = [base_date - datetime.timedelta(days=i) for i in range(n)]
 dates.reverse()
 # ランダムな価格データを生成
 rand = np.random.default_rng().uniform
 open = [100]
 high = [100.02]
 low = [100.02]
 close = [100.05]
 for i in range(n-1):
 open.append(close[i])
 close.append(open[-1] + rand(-0.1, 0.1))
 high.append(max(open[-1],close[-1]) + rand(0, 0.05))
 low.append(min(open[-1],close[-1]) - rand(0, 0.05))
 # DataFrameに格納
 ohlc_data = pd.DataFrame({
 "date": dates,
 "open": open,
 "high": high,
 "low": low,
 "close": close
 })
 return ohlc_data.set_index("date", drop=True)
period_range = 50
df = generate_sample_ohlc_data(period_range)
df["signal"] = np.nan
print(df)
some_signal = mpf.make_addplot(df["signal"])
mpf.plot(df, type='candle', addplot=some_signal) # ValueError

Currently, we have worked around this by doing NaN pre-checking on the user side, but it would be great if the library could handle this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /