Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ adheres to [Semantic Versioning](https://semver.org/).
## [Unreleased]

### Fixed
- `fd.clean` on a Spark DataFrame no longer raises
`TypeError: cannot materialize source of type DataFrame`. Under the default
`strategy="balanced"` the pandas fallback now materializes a Spark source
through its `toPandas()` method, alongside the existing polars and DuckDB
paths.
- `fd.evaluate_quality_debt` no longer scores a dimension a clean 0.0 when it
was never measured. `type_instability` when profiling fails, `pii_risk` when
the PII scan is unavailable or fails, and `schema_drift` and `category_churn`
Expand Down
5 changes: 5 additions & 0 deletions src/freshdata/execution/backends/_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ def materialize_to_pandas(source: Any) -> pd.DataFrame:
to_df = getattr(source, "df", None)
if callable(to_df):
return to_df()
# Spark DataFrame (collects to the driver, matching the balanced-strategy
# pandas fallback for a Spark source).
to_pandas_spark = getattr(source, "toPandas", None)
if callable(to_pandas_spark):
return to_pandas_spark()
raise TypeError(f"cannot materialize source of type {type(source).__name__}")


Expand Down
17 changes: 17 additions & 0 deletions tests/test_execution/test_dispatch_and_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,20 @@ def test_engine_config_spark_options():
spark_shuffle_partitions=4)
assert cfg.spark_shuffle_partitions == 4
assert cfg.output_format == "spark"


def test_materialize_to_pandas_accepts_spark_style_frame():
"""A Spark DataFrame exposes ``toPandas`` (not ``to_pandas``/``df``); the
balanced-strategy pandas fallback must materialize it, not raise TypeError."""
import pandas as pd

from freshdata.execution.backends._pandas import materialize_to_pandas

expected = pd.DataFrame({"a": [1, 2, 3], "b": ["x", "y", "z"]})

class _FakeSparkFrame:
def toPandas(self) -> pd.DataFrame: # noqa: N802 - matches pyspark's API
return expected.copy()

out = materialize_to_pandas(_FakeSparkFrame())
pd.testing.assert_frame_equal(out, expected)
Loading