Skip to content

BUG: Serialization Methods handling DataFrame NaNs differently #75

@abbas-mohd56

Description

@abbas-mohd56

Problem
When a highcharts series is created from a pandas DataFrame(), If the DataFrame contains any NaN or None values, The to_json() & to_dict() methods return a "null" string. The to_js_literal() however returns a correct null value.

Example

# Sample DataFrame saved in df
timestamp       value
1680307200000     NaN
1680393600000  5757.0
1680480000000  6521.0

After creating Highcharts series using series = LineSeries.from_pandas(df,property_map={"x": "timestamp", "y": "value"})

# series.to_js_literal() outputs
"{
  data: [{
  x: 1680307200000,
  y: null
},
{
  x: 1680393600000,
  y: 5757.0
},
{
  x: 1680480000000,
  y: 6521.0
}],
  type: 'column'
}"

# series.to_dict() outputs
{'data': [{'x': 1680307200000, 'y': 'null'}, {'x': 1680393600000, 'y': 5757.0}, {'x': 1680480000000, 'y': 6521.0}], 'type': 'column'}

# series.to_json() ouputs
"{"data": [{"x": 1680307200000, "y": "null"}, {"x": 1680393600000, "y": 5757.0}, {"x": 1680480000000, "y": 6521.0}], "type": "column"}"

Expected behavior
I'm not sure if this is by design but I was expecting to_dict() to return None & to_json to return null (Without quotes).
While the to_json() method can be parsed on the frontend using JSON.parse(), the series won't plot because the the value 'null' is treated as a string and adding series to the chart wouldn't plot anything.

Environment:

  • OS: Linux
  • Python Version: 3.10.8
  • Highcharts Python Version: 1.2.3

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions