From 057e0a214839a8de12c91061e891df6de6c2ae35 Mon Sep 17 00:00:00 2001 From: Chris Modzelewski Date: Wed, 8 May 2024 09:09:02 -0400 Subject: [PATCH 1/3] Added unit test for #169 --- tests/options/series/data/test_cartesian.py | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/options/series/data/test_cartesian.py b/tests/options/series/data/test_cartesian.py index 8bd0e54e..d6128181 100644 --- a/tests/options/series/data/test_cartesian.py +++ b/tests/options/series/data/test_cartesian.py @@ -1417,3 +1417,36 @@ def test_CartesianValueData_to_array(input_array, set_props, expected_type, expe if expected_type == list: assert results == expected + + +def test_BugFix_forum192819(): + from highcharts_core import highcharts + import pandas as pd + import numpy as np + + dates = [ + "30/04/2024", + "30/04/2024", + "26/04/2024", + "12/04/2024", + "31/03/2024", + "31/03/2024", + "29/03/2024", + "15/03/2024", + "05/03/2024", + ] + amounts = 100 + np.random.normal(loc=100, scale=10, size=len(dates)) + + df = pd.DataFrame([{"date": x, "amount": y} for x, y in zip(dates, amounts)]) + df["date"] = pd.to_datetime(df["date"], format="%d/%m/%Y") + df["milliseconds"] = (df["date"] - pd.Timestamp("1970-01-01")) // pd.Timedelta("1ms") + + my_chart = highcharts.Chart.from_pandas( + df, property_map={"x": "milliseconds", "y": "amount"}, series_type="line" + ) + + as_json = my_chart.to_json() + assert as_json is not None + + my_new_chart = highcharts.Chart.from_json(as_json) + assert my_new_chart is not None \ No newline at end of file From 42862c92a2548a0d2a3ddb94dac67386e3794534 Mon Sep 17 00:00:00 2001 From: Chris Modzelewski Date: Wed, 8 May 2024 09:09:29 -0400 Subject: [PATCH 2/3] Implemented to_json/from_json roundtrip bugfix. Closes #169. --- highcharts_core/options/series/data/base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/highcharts_core/options/series/data/base.py b/highcharts_core/options/series/data/base.py index 22813de1..d742ea63 100644 --- a/highcharts_core/options/series/data/base.py +++ b/highcharts_core/options/series/data/base.py @@ -704,6 +704,8 @@ def from_array(cls, value): if checkers.is_type(value, 'DataPointCollection'): return value + elif isinstance(value, dict) and 'dataPoints' in value: + return cls.from_list(value['dataPoints']) return cls.from_list(value) From 4029075c9b68ebf36cfd3f1257083805d8b2cc8e Mon Sep 17 00:00:00 2001 From: Chris Modzelewski Date: Wed, 8 May 2024 09:09:42 -0400 Subject: [PATCH 3/3] Bumped version number and updated changelog. --- CHANGES.rst | 7 +++++++ highcharts_core/__version__.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 38eee4f0..1cf84104 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,4 +1,11 @@ +Release 1.7.1 +========================================= + +* **BUGFIX:** Fixed data collection roundtrip via ``.to_json()`` / ``.from_json()`` (#169). + +-------------------- + Release 1.7.0 ========================================= diff --git a/highcharts_core/__version__.py b/highcharts_core/__version__.py index 0e1a38d3..48c2f6b0 100644 --- a/highcharts_core/__version__.py +++ b/highcharts_core/__version__.py @@ -1 +1 @@ -__version__ = '1.7.0' +__version__ = '1.7.1'