Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve load times by making import optional #3748

Merged
merged 1 commit into from
Jan 30, 2025
Merged
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
15 changes: 8 additions & 7 deletions sqlmesh/core/test/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import numpy as np
import pandas as pd
import time_machine
from io import StringIO
from pandas.api.types import is_object_dtype
from sqlglot import Dialect, exp
Expand Down Expand Up @@ -670,13 +669,15 @@ def runTest(self) -> None:

def _execute_model(self) -> pd.DataFrame:
"""Executes the python model and returns a DataFrame."""
time_ctx = (
time_machine.travel(self._execution_time, tick=False)
if self._execution_time
else nullcontext()
)
if self._execution_time:
import time_machine

time_ctx: AbstractContextManager = time_machine.travel(self._execution_time, tick=False)
else:
time_ctx = nullcontext()

with patch.dict(self._test_adapter_dialect.generator_class.TRANSFORMS, self._transforms):
with t.cast(AbstractContextManager, time_ctx):
with time_ctx:
variables = self.body.get("vars", {}).copy()
time_kwargs = {
key: variables.pop(key) for key in TIME_KWARG_KEYS if key in variables
Expand Down