diff --git a/ibis/expr/api.py b/ibis/expr/api.py index 6ec3e8e36c6c..f8aca6d68939 100644 --- a/ibis/expr/api.py +++ b/ibis/expr/api.py @@ -2237,7 +2237,9 @@ def _timestamp_range( step: datetime.timedelta | ir.IntervalValue, ) -> ir.ArrayValue: return ops.TimestampRange( - start=normalize_datetime(start), stop=normalize_datetime(stop), step=step + start=normalize_datetime(start) if isinstance(start, str) else start, + stop=normalize_datetime(stop) if isinstance(stop, str) else stop, + step=step, ).to_expr() diff --git a/ibis/tests/expr/test_timestamp.py b/ibis/tests/expr/test_timestamp.py index 45b8972d5dc4..f24bd91718f4 100644 --- a/ibis/tests/expr/test_timestamp.py +++ b/ibis/tests/expr/test_timestamp.py @@ -1,6 +1,6 @@ from __future__ import annotations -from datetime import datetime +from datetime import datetime, timedelta import numpy as np import pandas as pd @@ -184,3 +184,39 @@ def test_timestamp_field_access_on_time_failure( def test_integer_timestamp_fails(value): with pytest.raises(TypeError, match=r"Use ibis\.literal\(\.\.\.\)\.to_timestamp"): ibis.timestamp(value) + + +@pytest.mark.parametrize( + "start", + [ + "2002-01-01 00:00:00", + datetime(2002, 1, 1, 0, 0, 0), + ibis.timestamp("2002-01-01 00:00:00"), + ibis.timestamp(datetime(2002, 1, 1, 0, 0, 0)), + ibis.table({"start": "timestamp"}).start, + ], +) +@pytest.mark.parametrize( + "stop", + [ + "2002-01-02 00:00:00", + datetime(2002, 1, 2, 0, 0, 0), + ibis.timestamp("2002-01-02 00:00:00"), + ibis.timestamp(datetime(2002, 1, 2, 0, 0, 0)), + ibis.table({"stop": "timestamp"}).stop, + ], +) +@pytest.mark.parametrize("step", [ibis.interval(seconds=1), timedelta(seconds=1)]) +def test_timestamp_range_with_str_inputs(start, stop, step): + expr = ibis.range(start, stop, step) + + op = expr.op() + + assert op.start.dtype.is_timestamp() + assert op.stop.dtype.is_timestamp() + assert op.step.dtype.is_interval() + + dtype = expr.type() + + assert dtype.is_array() + assert dtype.value_type.is_timestamp()