diff --git a/CHANGES.rst b/CHANGES.rst index 38eee4f..1cf8410 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 0e1a38d..48c2f6b 100644 --- a/highcharts_core/__version__.py +++ b/highcharts_core/__version__.py @@ -1 +1 @@ -__version__ = '1.7.0' +__version__ = '1.7.1' diff --git a/highcharts_core/options/series/data/base.py b/highcharts_core/options/series/data/base.py index 22813de..d742ea6 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) diff --git a/tests/options/series/data/test_cartesian.py b/tests/options/series/data/test_cartesian.py index 8bd0e54..d612818 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