Repository: TobikoData/sqlmesh
Pull request #2773 (2024-06-14 13:14:20)

Fix: pass dialect to debug terminal console
Missed this one in https://github.com/TobikoData/sqlmesh/commit/a2b4d9db9cf842dfcb9cf7aeb2a6e28182c2ca10.


Patch:
diff --git a/sqlmesh/core/console.py b/sqlmesh/core/console.py
index a46ace67..88d4111d 100644
--- a/sqlmesh/core/console.py
+++ b/sqlmesh/core/console.py
@@ -1739,8 +1739,15 @@ class DatabricksMagicConsole(CaptureTerminalConsole):
 class DebuggerTerminalConsole(TerminalConsole):
     """A terminal console to use while debugging with no fluff, progress bars, etc."""
 
-    def __init__(self, console: t.Optional[RichConsole], *args: t.Any, **kwargs: t.Any) -> None:
+    def __init__(
+        self,
+        console: t.Optional[RichConsole],
+        *args: t.Any,
+        dialect: DialectType = None,
+        **kwargs: t.Any,
+    ) -> None:
         self.console: RichConsole = console or srich.console
+        self.dialect = dialect
 
     def _write(self, msg: t.Any, *args: t.Any, **kwargs: t.Any) -> None:
         self.console.log(msg, *args, **kwargs)
diff --git a/sqlmesh/core/model/definition.py b/sqlmesh/core/model/definition.py
index aa3eaa40..556d8b00 100644
--- a/sqlmesh/core/model/definition.py
+++ b/sqlmesh/core/model/definition.py
@@ -10,6 +10,7 @@ from functools import cached_property
 from pathlib import Path
 
 import pandas as pd
+import numpy as np
 from astor import to_source
 from pydantic import Field
 from sqlglot import diff, exp
@@ -1172,6 +1173,7 @@ class SeedModel(_SqlBasedModel):
         datetime_columns = []
         bool_columns = []
         string_columns = []
+
         for name, tpe in (self.columns_to_types_ or {}).items():
             if tpe.this in (exp.DataType.Type.DATE, exp.DataType.Type.DATE32):
                 date_columns.append(name)
@@ -1196,7 +1198,7 @@ class SeedModel(_SqlBasedModel):
                 cond=lambda x: x.notna(),  # type: ignore
                 other=df[string_columns].astype(str),  # type: ignore
             )
-            yield df
+            yield df.replace({np.nan: None})
 
     @property
     def columns_to_types(self) -> t.Optional[t.Dict[str, exp.DataType]]:


Test patch:
diff --git a/tests/core/test_model.py b/tests/core/test_model.py
index 76baccc3..3baf9a30 100644
--- a/tests/core/test_model.py
+++ b/tests/core/test_model.py
@@ -851,8 +851,8 @@ def test_seed_model_custom_types(tmp_path):
 
     with open(model_csv_path, "w", encoding="utf-8") as fd:
         fd.write(
-            """key,ds_date,ds_timestamp,b_a,b_b,i,i_str
-123,2022-01-01,2022-01-01,false,0,321,321
+            """key,ds_date,ds_timestamp,b_a,b_b,i,i_str,empty_date
+123,2022-01-01,2022-01-01,false,0,321,321,
 """
         )
 
@@ -867,6 +867,7 @@ def test_seed_model_custom_types(tmp_path):
             "b_b": "boolean",
             "i": "int",
             "i_str": "text",
+            "empty_date": "date",
         },
     )
 
@@ -893,6 +894,9 @@ def test_seed_model_custom_types(tmp_path):
     assert df["i_str"].dtype == "object"
     assert df["i_str"].iloc[0] == "321"
 
+    assert df["empty_date"].dtype == "object"
+    assert df["empty_date"].iloc[0] is None
+
 
 def test_seed_with_special_characters_in_column(tmp_path, assert_exp_eq):
     config = Config(model_defaults=ModelDefaultsConfig(dialect="duckdb"))