Skip to content

Commit

Permalink
chore: improve load times by making import optional (#3748)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao authored Jan 30, 2025
1 parent b735930 commit fc746b2
Showing 1 changed file with 8 additions and 7 deletions.
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

0 comments on commit fc746b2

Please sign in to comment.