tsio/guard: add a safety belt for non-datetime indexes
2 files changed, 3 insertions(+), 1 deletions(-)

M test/test_tsio.py
M tshistory/tsio.py
M test/test_tsio.py +1 -1
@@ 90,7 90,7 @@ def test_bogus_index(engine, tsh):
         [1, 2, 3],
         index=['2021-1-1', '2021-1-2', '2021-1-3'],
     )
-    with pytest.raises(AttributeError):
+    with pytest.raises(AssertionError):
         tsh.update(engine, ts, 'badindex', 'Babar')
 
 

          
M tshistory/tsio.py +2 -0
@@ 6,6 6,7 @@ import json
 from pathlib import Path
 
 import pandas as pd
+import numpy as np
 
 from sqlhelp import sqlfile, select, insert
 

          
@@ 543,6 544,7 @@ class timeseries:
                 isinstance(insertion_date, datetime)), 'Bad format for insertion date'
         assert isinstance(newts, pd.Series), 'Not a pd.Series'
         index = newts.index
+        assert isinstance(index, pd.DatetimeIndex), 'You must provide a DatetimeIndex'
         assert not index.duplicated().any(), 'There are some duplicates in the index'
 
         assert index.notna().all(), 'The index contains NaT entries'