From 8d72023dc44ee9f346c0caa458cd2db4c00cbf54 Mon Sep 17 00:00:00 2001 From: pjkroll <47292055+pjkroll@users.noreply.github.com> Date: Fri, 20 Feb 2026 13:41:02 +0100 Subject: [PATCH 1/3] Fix subcharts in JupyterChart --- lightweight_charts/widgets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lightweight_charts/widgets.py b/lightweight_charts/widgets.py index c347c45d..10bf72f5 100644 --- a/lightweight_charts/widgets.py +++ b/lightweight_charts/widgets.py @@ -164,7 +164,7 @@ def _load(self): class JupyterChart(StaticLWC): - def __init__(self, width: int = 800, height=350, inner_width=1, inner_height=1, scale_candles_only: bool = False, toolbox: bool = False): + def __init__(self, width: int = 800, height=350, inner_width: float=1.0, inner_height: float=1.0, scale_candles_only: bool = False, toolbox: bool = False): super().__init__(width, height, inner_width, inner_height, scale_candles_only, toolbox, False) self.run_script(f''' @@ -177,7 +177,7 @@ def __init__(self, width: int = 800, height=350, inner_width=1, inner_height=1, document.getElementById('container').style.width = '{self.width}px' document.getElementById('container').style.height = '100%' ''') - self.run_script(f'{self.id}.chart.resize({width}, {height})') + self.run_script(f'{self.id}.chart.resize({width * inner_width}, {height * inner_height})') def _load(self): if HTML is None: From b42827ad9c972096f8d6ba0ee5d88abfbb5caaf1 Mon Sep 17 00:00:00 2001 From: pjkroll <47292055+pjkroll@users.noreply.github.com> Date: Tue, 24 Feb 2026 13:24:27 +0100 Subject: [PATCH 2/3] Fix datetime to int64 Unix timestamp conversion, handling ns/us/ms units --- lightweight_charts/abstract.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lightweight_charts/abstract.py b/lightweight_charts/abstract.py index 0091d3f2..dc04c6ac 100644 --- a/lightweight_charts/abstract.py +++ b/lightweight_charts/abstract.py @@ -198,9 +198,14 @@ def _df_datetime_format(self, df: pd.DataFrame, exclude_lowercase=None): df = df.copy() df.columns = self._format_labels(df, df.columns, df.index, exclude_lowercase) self._set_interval(df) + if not pd.api.types.is_datetime64_any_dtype(df['time']): df['time'] = pd.to_datetime(df['time']) - df['time'] = df['time'].astype('int64') // 10 ** 9 + + unit = str(df['time'].dtype).split('[')[-1][:-1] # ns, us, ms, s + divisor = {'ns': 10**9, 'us': 10**6, 'ms': 10**3, 's': 1}[unit] + + df['time'] = df['time'].astype('int64') // divisor return df def _series_datetime_format(self, series: pd.Series, exclude_lowercase=None): From 34e51e16d1542a8b0e75daac167b47980e7e55bb Mon Sep 17 00:00:00 2001 From: pjkroll <47292055+pjkroll@users.noreply.github.com> Date: Tue, 24 Feb 2026 14:31:21 +0100 Subject: [PATCH 3/3] Refactor time conversion to use fixed nanoseconds with tz None --- lightweight_charts/abstract.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lightweight_charts/abstract.py b/lightweight_charts/abstract.py index dc04c6ac..1e7ea6d0 100644 --- a/lightweight_charts/abstract.py +++ b/lightweight_charts/abstract.py @@ -202,10 +202,9 @@ def _df_datetime_format(self, df: pd.DataFrame, exclude_lowercase=None): if not pd.api.types.is_datetime64_any_dtype(df['time']): df['time'] = pd.to_datetime(df['time']) - unit = str(df['time'].dtype).split('[')[-1][:-1] # ns, us, ms, s - divisor = {'ns': 10**9, 'us': 10**6, 'ms': 10**3, 's': 1}[unit] + df['time'] = pd.to_datetime(df['time']).dt.tz_localize(None).astype('datetime64[ns]') - df['time'] = df['time'].astype('int64') // divisor + df['time'] = df['time'].astype('int64') // 10**9 return df def _series_datetime_format(self, series: pd.Series, exclude_lowercase=None):