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] 2.1 Error when trying to delete lines #513

Open
sebinho opened this issue Jan 31, 2025 · 0 comments
Open

[BUG] 2.1 Error when trying to delete lines #513

sebinho opened this issue Jan 31, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@sebinho
Copy link

sebinho commented Jan 31, 2025

Expected Behavior

Hi,

I am writing this issue to flag an issue that used to work in 2.0.1 but does not work in 2.1.
When I try to delete an existing line it returns an error.
The original issue is here: #388

Current Behaviour

It is easy to reproduce by simply creating a line and then trying to remove it with following command:

for line in self.chart.lines():
            line.delete()

I get the following error.

Exception in thread Thread-2 (loop):
Traceback (most recent call last):
  File "/home/zed/repos/trading_sw/.env/lib/python3.12/site-packages/lightweight_charts/chart.py", line 89, in loop
    window.evaluate_js(arg)
  File "/home/zed/repos/trading_sw/.env/lib/python3.12/site-packages/webview/window.py", line 50, in wrapper
    return function(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/zed/repos/trading_sw/.env/lib/python3.12/site-packages/webview/window.py", line 487, in evaluate_js
    raise JavascriptException(result)
webview.errors.JavascriptException: {'name': 'NotFoundError', 'line': 6, 'column': 55, 'stack': 'removeChild@[native code]\neval code@\neval@[native code]\nglobal code@http://127.0.0.1:60360/index.html:4:33'}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.12/threading.py", line 1012, in run
    self._target(*self._args, **self._kwargs)
  File "/home/zed/repos/trading_sw/.env/lib/python3.12/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: 'message'

See below for a reproducible example.

Reproducible Example

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()
    chart.legend(visible=True)

    df = pd.read_csv('/home/zed/Downloads/ohlcv.csv')
    chart.set(df)

    line = chart.create_line('SMA 50')
    sma_data = calculate_sma(df, period=50)
    line.set(sma_data)

    for line in chart.lines():
        line.delete()

    chart.show(block=True)

Environment

Any
@sebinho sebinho added the bug Something isn't working label Jan 31, 2025
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