louisnw01 / lightweight-charts-python

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

chart.update() broken with newest pandas #103

Closed YanChii closed 1 year ago

YanChii commented 1 year ago

Hi,

thank you for your excellent job with this lib. I've just found it.

I'm letting you know that the pandas 2.1.0 (from 30th Aug 2023) has changed something with datetime processing and even your examples (2 and 3) throw error. Something like

chart.update_from_tick(series, cumulative_volume=True)

--->

Traceback (most recent call last):
  File "/backtester/main.py", line 22, in <module>
    chart.update_from_tick(series, cumulative_volume=True)
  File "/backtester/env.mac2/lib/python3.9/site-packages/lightweight_charts/abstract.py", line 505, in update_from_tick
    series = self._series_datetime_format(series)
  File "/backtester/env.mac2/lib/python3.9/site-packages/lightweight_charts/abstract.py", line 154, in _series_datetime_format
    series['time'] = self._single_datetime_format(series['time'])
  File "/backtester/env.mac2/lib/python3.9/site-packages/lightweight_charts/abstract.py", line 158, in _single_datetime_format
    if not pd.api.types.is_datetime64_any_dtype(arg):
  File "/backtester/env.mac2/lib/python3.9/site-packages/pandas/core/dtypes/common.py", line 890, in is_datetime64_any_dtype
    tipo = _get_dtype(arr_or_dtype)
  File "/backtester/env.mac2/lib/python3.9/site-packages/pandas/core/dtypes/common.py", line 1422, in _get_dtype
    return pandas_dtype(arr_or_dtype)
  File "/backtester/env.mac2/lib/python3.9/site-packages/pandas/core/dtypes/common.py", line 1636, in pandas_dtype
    npdtype = np.dtype(dtype)
  File "/backtester/env.mac2/lib/python3.9/site-packages/numpy/core/_internal.py", line 176, in _commastring
    raise ValueError(
ValueError: format number 1 of "2023-09-02 02:00:00+02:00" is not recognized

I've got a bit lost in tracking the problem but hopefully you'll have more luck.

Thanks.

Jan

louisnw01 commented 1 year ago

Hey @YanChii,

@jamesbaber1 brought this to my attention a few days ago; has been fixed in the latest version.

Louis