Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report: Errors occur for NaN columns. #672

Open
z4m1 opened this issue May 26, 2024 · 0 comments
Open

Bug Report: Errors occur for NaN columns. #672

z4m1 opened this issue May 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@z4m1
Copy link

z4m1 commented May 26, 2024

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.

@z4m1 z4m1 added the bug Something isn't working label May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant