Skip to content

fix(to_sql): write empty datasets so if_exists="replace" replaces the… - #9293

Open
Sailaja-ASB wants to merge 1 commit into
huggingface:mainfrom
Sailaja-ASB:fix-to-sql-empty-replace
Open

Sailaja-ASB wants to merge 1 commit into
huggingface:mainfrom
Sailaja-ASB:fix-to-sql-empty-replace

Conversation

@Sailaja-ASB

Copy link
Copy Markdown

Fixes #9289

An empty dataset never enters the batch loop in SqlDatasetWriter._write, so the pandas writer never runs and Dataset.to_sql(if_exists="replace") leaves an existing table (and its stale rows) untouched.

This adds a guard at the start of _write: for an empty dataset, it calls _batch_sql once with offset 0, which keeps the original to_sql_kwargs (so if_exists="replace" is preserved) and lets pandas create/replace an empty table with the correct columns. This single direct call covers both the serial and parallel paths without spawning a pool for an empty dataset.

No test suite was run.

… table

Handle empty dataset case in SQL writing process.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dataset.to_sql with if_exists="replace" retains stale rows when the dataset is empty

1 participant