highcharts-core
highcharts-core copied to clipboard
Change in series format since v1.4.0
The bug
When creating any series object using the from_pandas method, the format of the data attribute is different. Please refer to the Example to see the change.
Example
Let's say our DataFrame df is populated with the following data:
name value
0 lion 59
1 monkey 87
2 snake 51
3 giraffe 8
4 bear 47
If I generate a series using the following code
from highcharts_core.options.series.bar import BarSeries
BarSeries.from_pandas(df, property_map={"x": "name", "y": "value"})
I get the following output in different versions: v1.3.7 :
BarSeries(data = [{'y': 3, 'name': 'dog'}, {'y': 95, 'name': 'giraffe'}, {'y': 4, 'name': 'lion'}, {'y': 7, 'name': 'bear'}, {'y': 30, 'name': 'monkey'}], type = 'bar')
v1.4.0 & above:
BarSeries(data = {'dataPoints': [{'y': 3, 'name': 'dog'}, {'y': 95, 'name': 'giraffe'}, {'y': 4, 'name': 'lion'}, {'y': 7, 'name': 'bear'}, {'y': 30, 'name': 'monkey'}]}, name = 'value', type = 'bar')
To reproduce Run this python script to reproduce the issue
import pandas as pd
import random
from highcharts_core.options.series.bar import BarSeries
# List of animal names
animal_names = ['dog', 'cat', 'lion', 'elephant', 'giraffe', 'zebra', 'monkey', 'tiger', 'snake', 'bear']
# Generate random data
data = {
'name': random.sample(animal_names, 5),
'value': [random.randint(1, 100) for _ in range(5)],
}
# Create DataFrame
df = pd.DataFrame(data)
# Create series
series = BarSeries.from_pandas(df, property_map={"x": "name", "y": "value"})
Environment:
- OS: Linux
- Python Version: 3.10.13
- Highcharts JavaScript Version: 11.2
Additional context
Just to give you an idea on how I use this, once I have the series object build, I use the object's to_json method to serialize it. Then on the frontend script I prase it using JSON.parse() and add it the chart using Highchart's addSeries method
Any update on this?