louisnw01 / lightweight-charts-python

Python framework for TradingView's Lightweight Charts JavaScript library.
MIT License
1.12k stars 208 forks source link

Same error as #414 occured while trying to delete a line #465

Open tphlru opened 2 weeks ago

tphlru commented 2 weeks ago

Same error occurred while trying to delete a line. Reproducible Example

Minimal reproducible example:

import time

import pandas as pd
from lightweight_charts import Chart

def calculate_sma(df, period: int = 50):
    return pd.DataFrame(
        {"time": df["date"], f"SMA {period}": df["close"].rolling(window=period).mean()}
    ).dropna()

if __name__ == "__main__":
    chart = Chart()
    line = chart.create_line(name="SMA 20")

    df = pd.read_csv("ohlcv.csv")
    sma_df = calculate_sma(df, period=20)

    chart.set(df)
    line.set(sma_df)
    time.sleep(5)

    line.delete()

    chart.show(block=True)

Error

Exception in thread Thread-2 (loop):
Traceback (most recent call last):
  File "C:\Users\serge\.conda\envs\bt24\Lib\site-packages\lightweight_charts\chart.py", line 89, in loop
    window.evaluate_js(arg)
  File "C:\Users\serge\.conda\envs\bt24\Lib\site-packages\webview\window.py", line 50, in wrapper
    return function(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\serge\.conda\envs\bt24\Lib\site-packages\webview\window.py", line 455, in evaluate_js
    raise JavascriptException(result)
webview.errors.JavascriptException: {'name': 'NotFoundError', 'stack': "Error: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.\n    at eval (eval at <anonymous> (:4:29), <anonymous>:56598:44)\n    at <anonymous>:4:29"}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\serge\.conda\envs\bt24\Lib\threading.py", line 1075, in _bootstrap_inner
    self.run()
  File "C:\Users\serge\.conda\envs\bt24\Lib\threading.py", line 1012, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\serge\.conda\envs\bt24\Lib\site-packages\lightweight_charts\chart.py", line 94, in loop
    raise JavascriptException(f"\n\nscript -> '{arg}',\nerror -> {msg['name']}[{msg['line']}:{msg['column']}]\n{msg['message']}")
                                                                                ~~~^^^^^^^^
KeyError: 'line'

Enviroment configuration:

pip list
Package                     Version
--------------------------- -----------
anyio                       4.4.0
asttokens                   2.4.1
backtrader                  1.9.78.123
bottle                      0.13.1
certifi                     2024.8.30
cffi                        1.17.1
clr-loader                  0.2.6
colorama                    0.4.6
comm                        0.2.2
contourpy                   1.3.0
cramjam                     2.8.3
cycler                      0.12.1
debugpy                     1.6.7
decorator                   5.1.1
dynaconf                    3.2.6
exceptiongroup              1.2.2
executing                   2.1.0
fastparquet                 2024.5.0
fonttools                   4.53.1
fsspec                      2024.9.0
h11                         0.14.0
httpcore                    1.0.5
httpx                       0.27.2
idna                        3.10
importlib_metadata          8.5.0
ipykernel                   6.29.5
ipython                     8.27.0
jedi                        0.19.1
jupyter_client              8.6.2
jupyter_core                5.7.2
keyboard                    0.13.5
kiwisolver                  1.4.7
lightweight-charts          2.1
matplotlib                  3.9.2
matplotlib-inline           0.1.7
moexalgo                    2.1.1
nest_asyncio                1.6.0
numpy                       1.26.4
packaging                   24.1
pandas                      2.2.3
parso                       0.8.4
pickleshare                 0.7.5
pillow                      10.4.0
pip                         24.2
platformdirs                4.3.3
prompt_toolkit              3.0.47
proxy_tools                 0.1.0
psutil                      5.9.0
pure_eval                   0.2.3
pyarrow                     17.0.0
pycparser                   2.22
Pygments                    2.18.0
pyparsing                   3.1.4
PyQt6-Qt6                   6.7.2
PyQt6_sip                   13.8.0
PyQt6-WebEngine-Qt6         6.7.2
PyQt6-WebEngineSubwheel-Qt6 6.7.2
python-dateutil             2.9.0.post0
python-telegram-bot         21.5
pythonnet                   3.0.4
pytz                        2024.2
pywebview                   5.2
pywin32                     305.1
pyzmq                       25.1.2
setuptools                  72.1.0
six                         1.16.0
sniffio                     1.3.1
stack-data                  0.6.2
TA-Lib                      0.4.32
tornado                     6.4.1
traitlets                   5.14.3
typing_extensions           4.12.2
tzdata                      2024.2
wcwidth                     0.2.13
wheel                       0.44.0
zipp                        3.20.2

Originally posted by @algotrading-py in https://github.com/louisnw01/lightweight-charts-python/issues/414#issuecomment-2391931535

Possible solution: https://github.com/louisnw01/lightweight-charts-python/issues/414#issuecomment-2391983200

safaritrader commented 6 days ago

usually i use this approach : line.set(None)