Skip to content

Commit 39ffd13

Browse files
committed
Implemented solution for GanttSeries.from_pandas() bug. Closes #46.
1 parent e38d46c commit 39ffd13

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

highcharts_gantt/options/series/data/gantt.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from highcharts_gantt.metaclasses import HighchartsMeta
1212
from highcharts_gantt.options.series.data.connect import DataConnection
1313
from highcharts_gantt.options.series.data.collections import DataPointCollection
14-
from highcharts_gantt.utility_functions import validate_color, parse_jira_issue
14+
from highcharts_gantt.utility_functions import validate_color, parse_jira_issue, datetime64_to_datetime
1515
from highcharts_gantt.utility_classes.gradients import Gradient
1616
from highcharts_gantt.utility_classes.patterns import Pattern
1717

@@ -218,7 +218,13 @@ def end(self, value):
218218
elif checkers.is_date(value):
219219
self._end = validators.date(value, allow_empty = True)
220220
else:
221-
self._end = validators.datetime(value, allow_empty = True, coerce_value = True)
221+
try:
222+
self._end = validators.datetime(value, allow_empty = True, coerce_value = True)
223+
except (ValueError, TypeError) as error:
224+
if checkers.is_type(value, 'datetime64'):
225+
self._end = datetime64_to_datetime(value)
226+
else:
227+
raise error
222228

223229
@property
224230
def milestone(self) -> Optional[bool]:
@@ -279,7 +285,13 @@ def start(self, value):
279285
elif checkers.is_date(value):
280286
self._start = validators.date(value, allow_empty = True)
281287
else:
282-
self._start = validators.datetime(value, allow_empty = True, coerce_value = True)
288+
try:
289+
self._start = validators.datetime(value, allow_empty = True, coerce_value = True)
290+
except (ValueError, TypeError) as error:
291+
if checkers.is_type(value, 'datetime64'):
292+
self._start = datetime64_to_datetime(value)
293+
else:
294+
raise error
283295

284296
@property
285297
def y(self) -> Optional[int | float | Decimal]:

highcharts_gantt/options/series/gantt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,13 +1129,13 @@ def _data_collection_class(cls):
11291129
:rtype: :class:`DataPointCollection <highcharts_core.options.series.data.collections.DataPointCollection>`
11301130
descendent
11311131
"""
1132-
return GanttData
1133-
1132+
return GanttDataCollection
1133+
11341134
@classmethod
11351135
def _data_point_class(cls):
11361136
"""Returns the class object used for individual data points.
11371137
11381138
:rtype: :class:`DataBase <highcharts_core.options.series.data.base.DataBase>`
11391139
descendent
11401140
"""
1141-
return GanttDataCollection
1141+
return GanttData
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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,3 +655,25 @@ def test_to_dict(kwargs, error):
655655
])
656656
def test_from_js_literal(input_files, filename, as_file, error):
657657
Class_from_js_literal(cls, input_files, filename, as_file, error)
658+
659+
def test_bugfix162(input_files):
660+
from highcharts_gantt.chart import Chart
661+
from highcharts_gantt.options.series.gantt import GanttSeries
662+
663+
import pandas as pd
664+
from collections import defaultdict
665+
666+
filename = "series/base/bugfix162.csv"
667+
input_file = check_input_file(input_files, filename)
668+
669+
dtype = defaultdict(lambda: "str")
670+
671+
df = pd.read_csv(input_file, dtype=dtype, parse_dates=["start", "end"])
672+
673+
# Creating a Series from the DataFrame
674+
my_series = GanttSeries.from_pandas(
675+
df,
676+
property_map={"id": "task_id", "name": "name", "start": "start", "end": "end"},
677+
)
678+
679+
assert my_series is not None

0 commit comments

Comments
 (0)