Skip to content

Commit 4e86e48

Browse files
committed
Increment version to 2.5.1 and add temporal type validation
1 parent 7b99227 commit 4e86e48

File tree

6 files changed

+48
-2
lines changed

6 files changed

+48
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "traffic_anomaly"
7-
version = "2.5.0"
7+
version = "2.5.1"
88
authors = [
99
{ name="Shawn Strasser", email="shawn.strasser@odot.oregon.gov" },
1010
]

src/traffic_anomaly/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
__all__ = ['decompose', 'anomaly', 'changepoint']
77

8-
__version__ = '2.5.0'
8+
__version__ = '2.5.1'

src/traffic_anomaly/anomaly.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def _validate_columns(table: ibis.Expr, datetime_column: str, value_column: str,
2121
if missing_columns:
2222
raise ValueError(f"Missing required columns: {missing_columns}")
2323

24+
if not table[datetime_column].type().is_temporal():
25+
raise TypeError(f"Column '{datetime_column}' must be a temporal type (e.g., timestamp or date), but is {table[datetime_column].type()}")
26+
2427

2528
def anomaly(
2629
decomposed_data: Union[ibis.Expr, Any], # ibis.Expr or pandas.DataFrame

src/traffic_anomaly/changepoint.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def _validate_columns(table: ibis.Expr, datetime_column: str, value_column: str,
2525
if missing_columns:
2626
raise ValueError(f"Missing required columns: {missing_columns}")
2727

28+
if not table[datetime_column].type().is_temporal():
29+
raise TypeError(f"Column '{datetime_column}' must be a temporal type (e.g., timestamp or date), but is {table[datetime_column].type()}")
30+
2831

2932
def _calculate_changepoints_core(
3033
table: ibis.Expr,

src/traffic_anomaly/decompose.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def _validate_columns(table: ibis.Expr, datetime_column: str, value_column: str,
2121
if missing_columns:
2222
raise ValueError(f"Missing required columns: {missing_columns}")
2323

24+
if not table[datetime_column].type().is_temporal():
25+
raise TypeError(f"Column '{datetime_column}' must be a temporal type (e.g., timestamp or date), but is {table[datetime_column].type()}")
26+
2427

2528
def decompose(
2629
data: Union[ibis.Expr, Any], # ibis.Expr or pandas.DataFrame

tests/test_traffic_anomaly.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,43 @@ def test_decompose_invalid_data_type(self):
885885
entity_grouping_columns=['id']
886886
)
887887

888+
def test_invalid_timestamp_type(self):
889+
"""Test that providing a string timestamp raises a TypeError"""
890+
df_string_ts = pd.DataFrame({
891+
'timestamp': ['2023-01-01 00:00:00'],
892+
'value': [10],
893+
'id': ['A'],
894+
'prediction': [10],
895+
'resid': [0]
896+
})
897+
898+
# Test decompose
899+
with pytest.raises(TypeError, match="must be a temporal type"):
900+
traffic_anomaly.decompose(
901+
data=df_string_ts,
902+
datetime_column='timestamp',
903+
value_column='value',
904+
entity_grouping_columns=['id']
905+
)
906+
907+
# Test anomaly
908+
with pytest.raises(TypeError, match="must be a temporal type"):
909+
traffic_anomaly.anomaly(
910+
decomposed_data=df_string_ts,
911+
datetime_column='timestamp',
912+
value_column='value',
913+
entity_grouping_columns=['id']
914+
)
915+
916+
# Test changepoint
917+
with pytest.raises(TypeError, match="must be a temporal type"):
918+
traffic_anomaly.changepoint(
919+
data=df_string_ts,
920+
datetime_column='timestamp',
921+
value_column='value',
922+
entity_grouping_column='id'
923+
)
924+
888925
def test_anomaly_missing_columns(self):
889926
"""Test anomaly detection with missing required columns"""
890927
# Test missing datetime column

0 commit comments

Comments
 (0)