Skip to content

Commit 31ab453

Browse files
authored
Merge pull request #120 from highcharts-for-python/develop
PR for v.1.4.1
2 parents 26c20e3 + f9b4015 commit 31ab453

File tree

7 files changed

+65
-9
lines changed

7 files changed

+65
-9
lines changed

CHANGES.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11

2+
Release 1.4.1
3+
=========================================
4+
5+
* **BUGFIX:** Fixed handling of ``numpy.datetime64`` values in ``DataPointCollection``. (#118)
6+
7+
---------------------
8+
29
Release 1.4.0
310
=========================================
411

docs/using.rst

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -783,12 +783,26 @@ will display the chart in full.
783783

784784
.. warning::
785785

786-
The current version of **Highcharts for Python** assumes that your web content already
787-
has all the ``<script/>`` tags which include the
788-
`Highcharts (JS) <https://www.highcharts.com>`__ modules your chart relies on.
786+
The :meth:`.to_js_literal() <highcharts_core.chart.Chart.to_js_literal>` method
787+
assumes that your web content already has all the ``<script/>`` tags which include
788+
the `Highcharts (JS) <https://www.highcharts.com>`__ modules your chart relies on.
789789

790-
This is likely to change in a future version of **Highcharts for Python**, where the
791-
library will support the production of ``<script/>`` tags (see roadmap issue :issue:`12`).
790+
If you need to generate the required ``<script/>`` tags for your chart, you can do
791+
so by calling:
792+
793+
.. code-block:: python
794+
795+
# EXAMPLE 1.
796+
# Get a list of <script/> tags.
797+
list_of_script_tags = my_chart.get_script_tags()
798+
799+
# EXAMPLE 2.
800+
# Get a string of <script/> tags.
801+
script_tags_as_str = my_chart.get_script_tags(as_str = True)
802+
803+
# EXAMPLE 3.
804+
# Get a list of the required Highcharts modules.
805+
required_modules = my_chart.get_required_modules()
792806
793807
For example:
794808

highcharts_core/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.4.0'
1+
__version__ = '1.4.1'

highcharts_core/options/series/data/collections.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
from typing import Optional, List
23
from collections import UserDict
34

@@ -273,7 +274,18 @@ def __setattr__(self, name, value):
273274
try:
274275
setattr(data_points[index], name, value[index])
275276
except validator_errors.CannotCoerceError:
276-
if isinstance(value[index], str) and ',' in value[index]:
277+
if 'datetime64' in value[index].__class__.__name__:
278+
try:
279+
coerced_value = value[index].astype(datetime.datetime)
280+
IS_DATETIME = True
281+
except (ValueError, TypeError):
282+
IS_DATETIME = False
283+
else:
284+
IS_DATETIME = False
285+
286+
if IS_DATETIME:
287+
setattr(data_points[index], name, coerced_value)
288+
elif isinstance(value[index], str) and ',' in value[index]:
277289
coerced_value = value[index].replace(',', '')
278290
setattr(data_points[index], name, coerced_value)
279291
elif checkers.is_numeric(value[index]) or (

requirements.dev.numpy.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ sphinx-toolbox==3.4.0
1010
sphinx-tabs==3.4.1
1111
tox==4.4.6
1212
requests==2.31.0
13-
urllib3==1.26.9
1413
validator-collection==1.5.0
1514
anthropic==0.3.11
1615
dill==0.3.7

requirements.dev.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ sphinx-toolbox==3.4.0
1010
sphinx-tabs==3.4.1
1111
tox==4.4.6
1212
requests==2.31.0
13-
urllib3==1.26.9
1413
validator-collection==1.5.0
1514
anthropic==0.3.11
1615
dill==0.3.7

tests/options/series/test_area.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,6 +3116,31 @@ def test_LineSeries_from_csv(input_files, filename, property_map, kwargs, expect
31163116
**kwargs)
31173117

31183118

3119+
def test_Bugfix118_LineSeries_from_pandas_with_datetime():
3120+
import datetime as dt
3121+
try:
3122+
import pandas as pd
3123+
HAS_PANDAS = True
3124+
except ImportError:
3125+
HAS_PANDAS = False
3126+
3127+
if HAS_PANDAS:
3128+
# Generate timestamps for the first 5 days of October 2023
3129+
start_date = dt.datetime(2023, 10, 1)
3130+
end_date = dt.datetime(2023, 10, 5)
3131+
date_range = [start_date + dt.timedelta(days=i) for i in range(5)]
3132+
3133+
# Create a list of values
3134+
values = [10, 20, 30, 40, 50]
3135+
3136+
# Create a DataFrame
3137+
df = pd.DataFrame({'Timestamp': date_range, 'Value': values})
3138+
my_series = cls5.from_pandas(df, property_map={"x": "Timestamp", "y": "Value"})
3139+
3140+
assert my_series is not None
3141+
assert isinstance(my_series, cls5)
3142+
3143+
31193144
#### NEXT CLASS
31203145

31213146
@pytest.mark.parametrize('kwargs, error', STANDARD_PARAMS)

0 commit comments

Comments
 (0)