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'
Same error occurred while trying to delete a line. Reproducible Example
Minimal reproducible example:
Error
Enviroment configuration:
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