Skip to content

Commit 3e2642b

Browse files
committed
fix: handle zero-column DuckDB sources
1 parent d74e6cd commit 3e2642b

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎src/freshdata/execution/backends/_duckdb.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
)
4343
from .._plan import PlanGenerator
4444
from .._report import finalize_report, finalize_report_native, init_report, zero_column_frame
45+
from ...report import CleanReport
4546
from .._spill import create_run_spill_dir, remove_run_spill_dir
4647
from ._pandas import materialize_to_pandas
4748

4849
if TYPE_CHECKING: # pragma: no cover - typing only
4950
import pandas as pd
5051

5152
from ...config import CleanConfig
52-
from ...report import CleanReport
5353
from .._config import EngineConfig
5454

5555
log = logging.getLogger("freshdata.execution.duckdb")
@@ -147,6 +147,19 @@ def execute(
147147

148148
plan_cols = self._peek_columns(source)
149149
plan = PlanGenerator(config).plan(plan_cols)
150+
151+
if not plan_cols:
152+
started = time.perf_counter()
153+
report = CleanReport(
154+
rows_before=len(source),
155+
cols_before=0,
156+
memory_before=self._memory_before(source),
157+
)
158+
report.backend = "duckdb"
159+
cleaned = zero_column_frame("duckdb", engine_config.output_format, report)
160+
finalize_report(report, cleaned, started)
161+
return cleaned, report
162+
150163
reason = plan.fallback_reason or pandas_ingest_fallback_reason(source, self.name)
151164
if reason is None and self._pandas_index_forces_fallback(source):
152165
reason = "pandas index semantics"

‎tests/test_execution/test_duckdb_engine.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ def test_drop_empty_column(native_config):
5252
assert "empty" not in out.columns
5353

5454

55+
def test_zero_column_dataframe(native_config):
56+
df = pd.DataFrame(index=range(3))
57+
out = fd.clean(df, config=native_config, engine="duckdb")
58+
assert out.shape == (3, 0)
59+
60+
5561
def test_drop_duplicates(native_config):
5662
df = pd.DataFrame({"a": [1, 1, 2, 2, 3], "b": ["x", "x", "y", "y", "z"]})
5763
out = fd.clean(df, config=native_config, engine="duckdb", drop_duplicates=True)

0 commit comments

Comments
 (0)