Skip to content

Commit ae06c41

Browse files
authored
Merge pull request #164 from highcharts-for-python/bugfix/162-data-collection-propagation-validation-error
Closes #162.
2 parents 8a7c606 + c8df7b8 commit ae06c41

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

CHANGES.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11

2-
Release 1.6.0
2+
Release 1.7.0
33
=========================================
44

55
* **ENHANCEMENT:** Align the API to **Highcharts (JS) v.11.4** (#163). In particular, this includes:
6-
76
* Added ``Accessibility.high_contrast_mode`` support.
87
* Added ``OrganizationOptions.hanging_side`` support.
98
* Added ``SankeyOptions.node_distance`` support.
@@ -12,6 +11,9 @@ Release 1.6.0
1211
``SankeyOptions``) ``.node_width`` support and documentation.
1312
* Added ``NodeOptions.height`` support.
1413

14+
* **ENHANCEMENT:** Added ``utility_functions.datetime64_to_datetime()`` function to convert
15+
``numpy.datetime64`` to ``datetime.datetime`` (needed to close #162).
16+
1517
--------------------
1618

1719
Release 1.6.0

highcharts_core/utility_functions.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Collection of utility functions used across the library."""
22
import csv
3+
import datetime
34
import os
45
import string
56
import random
@@ -907,4 +908,29 @@ def dict_to_ndarray(as_dict):
907908
columns = [as_dict[key] for key in as_dict]
908909
as_ndarray = np.column_stack(columns)
909910

910-
return as_ndarray
911+
return as_ndarray
912+
913+
914+
def datetime64_to_datetime(dt64):
915+
"""Convert a NumPy :class:`datetime64 <numpy:numpy.datetime64>` to a Python
916+
:class:`datetime <python:datetime.datetime>`.
917+
918+
:param dt64: The NumPy :class:`datetime64 <numpy:numpy.datetime64>` to convert.
919+
:type dt64: :class:`numpy.datetime64 <numpy:numpy.datetime64>`
920+
921+
:returns: A Python :class:`datetime <python:datetime.datetime>` instance.
922+
:rtype: :class:`datetime <python:datetime.datetime>`
923+
924+
:raises HighchartsDependencyError: if NumPy is not available in the runtime
925+
environment
926+
927+
"""
928+
if not HAS_NUMPY:
929+
raise errors.HighchartsDependencyError('NumPy is required for this feature. '
930+
'It was not found in your runtime '
931+
'environment. Please make sure it is '
932+
'installed in your runtime '
933+
'environment.')
934+
timestamp = (dt64 - np.datetime64("1970-01-01T00:00:00")) / np.timedelta64(1, "s")
935+
936+
return datetime.datetime.fromtimestamp(timestamp, datetime.timezone.utc)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
task_id,name,start,end,parent,dependency
2+
1,DoThing1,2023-01-01,2023-02-01,,
3+
2,DoThing1-sub1,2023-01-11,2023-01-14,1,
4+
3,DoThing1-sub2,2023-01-01,2023-02-01,1,2
5+
4,DoThing2,2023-02-02,2023-03-01,,

tests/options/series/test_base.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,4 +923,27 @@ def test_convert_to(input_files, filename, target_type, as_cls, error):
923923
converted = original.convert_to(target_type)
924924
assert converted is not None
925925
assert isinstance(converted, SeriesBase)
926-
assert isinstance(converted, target_type_cls)
926+
assert isinstance(converted, target_type_cls)
927+
928+
929+
def test_bugfix162(input_files):
930+
from highcharts_core.chart import Chart
931+
from highcharts_core.options import HighchartsOptions
932+
from highcharts_core.options.series.area import LineSeries
933+
934+
import pandas as pd
935+
from collections import defaultdict
936+
937+
filename = 'series/base/bugfix162.csv'
938+
input_file = check_input_file(input_files, filename)
939+
940+
dtype = defaultdict(lambda: "str")
941+
942+
df = pd.read_csv(input_file, dtype=dtype, parse_dates=["start", "end"])
943+
944+
# Creating a Series from the DataFrame
945+
my_series = LineSeries.from_pandas(
946+
df, property_map={"id": "task_id", "name": "name", "start": "start", "end": "end"}
947+
)
948+
949+
assert my_series is not None

0 commit comments

Comments
 (0)