Skip to content
Open
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
2 changes: 2 additions & 0 deletions sqlmesh/utils/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ def make_exclusive(time: TimeLike) -> datetime:


def make_ts_exclusive(time: TimeLike, dialect: DialectType) -> datetime:
import pandas as pd

ts = to_datetime(time)
if dialect == "tsql":
return to_utc_timestamp(ts) - pd.Timedelta(1, unit="ns")
Expand Down
13 changes: 13 additions & 0 deletions tests/utils/test_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
is_categorical_relative_expression,
is_relative,
make_inclusive,
make_ts_exclusive,
to_datetime,
to_time_column,
to_timestamp,
to_ts,
to_tstz,
to_utc_timestamp,
)


Expand Down Expand Up @@ -141,6 +143,17 @@ def test_make_inclusive_tsql(start_in, end_in, start_out, end_out, dialect) -> N
)


def test_make_ts_exclusive() -> None:
# tsql subtracts 1ns from the UTC timestamp; must not raise NameError (pd not imported)
assert make_ts_exclusive("2020-01-01 12:00:00", dialect="tsql") == to_utc_timestamp(
to_datetime("2020-01-01 12:00:00")
) - pd.Timedelta(1, unit="ns")
# non-tsql dialects add 1 microsecond
assert make_ts_exclusive("2020-01-01 12:00:00", dialect="duckdb") == to_datetime(
"2020-01-01 12:00:00.000001"
)


@pytest.mark.parametrize(
"expression, result",
[
Expand Down
Loading