Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: keep a CSV seed's values as written when dropping its index column (#11945)

Lukas99101949ebea
diff --git a/studio/backend/routes/data_recipe/seed.py b/studio/backend/routes/data_recipe/seed.py
index 37c23dae1d7..7f18aa669cf 100644
--- a/studio/backend/routes/data_recipe/seed.py
+++ b/studio/backend/routes/data_recipe/seed.py
@@ -925,12 +925,19 @@ def _read_preview_rows_from_local_file(path: Path, preview_size: int) -> list[di
ext = path.suffix.lower()
try:
if ext == ".csv":
- df = pd.read_csv(path, nrows = preview_size, encoding = "utf-8-sig")
+ # Keep text as written: inference made 007 -> 7, 3 -> 3.0, NA/None -> missing.
+ csv_options = {
+ "encoding": "utf-8-sig",
+ "dtype": str,
+ "keep_default_na": False,
+ "na_values": [""],
+ }
+ df = pd.read_csv(path, nrows = preview_size, **csv_options)
df.columns = df.columns.str.strip()
unnamed = [c for c in df.columns if c == "" or c.startswith("Unnamed:")]
if unnamed:
df = df.drop(columns = unnamed)
- full_df = pd.read_csv(path, encoding = "utf-8-sig")
+ full_df = pd.read_csv(path, **csv_options)
full_df.columns = full_df.columns.str.strip()
full_df = full_df.drop(columns = unnamed)
tmp_csv = path.with_suffix(".tmp.csv")
diff --git a/studio/backend/tests/test_data_recipe_seed.py b/studio/backend/tests/test_data_recipe_seed.py
index 74d5f701e4c..a2fbdbeba29 100644
--- a/studio/backend/tests/test_data_recipe_seed.py
+++ b/studio/backend/tests/test_data_recipe_seed.py
@@ -82,6 +82,26 @@ def _raise(exc: BaseException):
return raise_exc
+def test_local_csv_seed_keeps_its_values_as_written(monkeypatch, tmp_path):
+ seed_route = _load_seed_route(monkeypatch, tmp_path)
+ monkeypatch.setattr(seed_route, "account_path", lambda path: None)
+ path = tmp_path / "seed.csv"
+ # The unnamed index column triggers the rewrite.
+ path.write_text(",zip,country,qty,note\n0,01234,NA,3,None\n1,90210,DE,,N/A\n", encoding = "utf-8")
+
+ rows = seed_route._read_preview_rows_from_local_file(path, 10)
+
+ assert [row["zip"] for row in rows] == ["01234", "90210"]
+ assert [row["country"] for row in rows] == ["NA", "DE"]
+ assert [row["note"] for row in rows] == ["None", "N/A"]
+ assert rows[0]["qty"] == "3"
+ assert path.read_text(encoding = "utf-8").splitlines() == [
+ "zip,country,qty,note",
+ "01234,NA,3,None",
+ "90210,DE,,N/A",
+ ]
+
+
@pytest.mark.parametrize(
("filename", "package"),
[