Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

Release 1.4.1
=========================================

* **BUGFIX:** Fixed handling of ``numpy.datetime64`` values in ``DataPointCollection``. (#118)

---------------------

Release 1.4.0
=========================================

Expand Down
2 changes: 1 addition & 1 deletion highcharts_core/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.4.0'
__version__ = '1.4.1'
14 changes: 13 additions & 1 deletion highcharts_core/options/series/data/collections.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
from typing import Optional, List
from collections import UserDict

Expand Down Expand Up @@ -273,7 +274,18 @@ def __setattr__(self, name, value):
try:
setattr(data_points[index], name, value[index])
except validator_errors.CannotCoerceError:
if isinstance(value[index], str) and ',' in value[index]:
if 'datetime64' in value[index].__class__.__name__:
try:
coerced_value = value[index].astype(datetime.datetime)
IS_DATETIME = True
except (ValueError, TypeError):
IS_DATETIME = False
else:
IS_DATETIME = False

if IS_DATETIME:
setattr(data_points[index], name, coerced_value)
elif isinstance(value[index], str) and ',' in value[index]:
coerced_value = value[index].replace(',', '')
setattr(data_points[index], name, coerced_value)
elif checkers.is_numeric(value[index]) or (
Expand Down
1 change: 0 additions & 1 deletion requirements.dev.numpy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ sphinx-toolbox==3.4.0
sphinx-tabs==3.4.1
tox==4.4.6
requests==2.31.0
urllib3==1.26.9
validator-collection==1.5.0
anthropic==0.3.11
dill==0.3.7
Expand Down
1 change: 0 additions & 1 deletion requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ sphinx-toolbox==3.4.0
sphinx-tabs==3.4.1
tox==4.4.6
requests==2.31.0
urllib3==1.26.9
validator-collection==1.5.0
anthropic==0.3.11
dill==0.3.7
Expand Down
25 changes: 25 additions & 0 deletions tests/options/series/test_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -3116,6 +3116,31 @@ def test_LineSeries_from_csv(input_files, filename, property_map, kwargs, expect
**kwargs)


def test_Bugfix118_LineSeries_from_pandas_with_datetime():
import datetime as dt
try:
import pandas as pd
HAS_PANDAS = True
except ImportError:
HAS_PANDAS = False

if HAS_PANDAS:
# Generate timestamps for the first 5 days of October 2023
start_date = dt.datetime(2023, 10, 1)
end_date = dt.datetime(2023, 10, 5)
date_range = [start_date + dt.timedelta(days=i) for i in range(5)]

# Create a list of values
values = [10, 20, 30, 40, 50]

# Create a DataFrame
df = pd.DataFrame({'Timestamp': date_range, 'Value': values})
my_series = cls5.from_pandas(df, property_map={"x": "Timestamp", "y": "Value"})

assert my_series is not None
assert isinstance(my_series, cls5)


#### NEXT CLASS

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