Skip to content

feat: enable typeset inference for pyspark - #1889

Open
fabclmnt wants to merge 1 commit into
developfrom
feat/typesetrules_spark_pandas
Open

fabclmnt wants to merge 1 commit into
developfrom
feat/typesetrules_spark_pandas

Conversation

@fabclmnt

@fabclmnt fabclmnt commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved Spark inference and casting defects can lose numeric precision, overwrite input columns, and produce incorrect categories, missing-value counts, and duplicate detection.

5 open issues
What changed in this PR

This PR enables type inference for PySpark profiling, using the existing typeset’s precedence and shared thresholds to align Spark behavior with pandas.

Changes:

  • Enable Spark inference by default and cast inferred columns for summaries and downstream analysis.
  • Share cardinality rules between backends and document Spark-specific parsing limitations.
  • Add Spark inference and casting tests, and consolidate pandas inference regression tests.
File Description
tests/​unit/​test_typeset_sampling.py Consolidates sampling tests and expands cast-equivalence checks.
tests/​unit/​test_typeset_precedence.py Consolidates precedence and traversal tests.
tests/​backends/​spark_backend/​test_typeset_spark.py Adds backend parity and inferred-schema tests.
src/​data_profiling/​model/​typeset_relations.py Uses shared cardinality rules for pandas inference.
src/​data_profiling/​model/​type_rules.py Defines backend-independent cardinality decisions.
src/​data_profiling/​model/​spark/​typeset_spark.py Implements Spark inference, parsing, and casting.
src/​data_profiling/​model/​spark/​summary_spark.py Applies inference before Spark column summaries.
src/​data_profiling/​model/​describe.py Casts Spark columns before downstream analysis.
src/​data_profiling/​config.py Enables inference by default in Spark settings.
docs/​features/​big_data.md Documents Spark inference, limitations, and opt-out configuration.

Review effort: Balanced

# DataFrame, so cast its columns to the inferred types.
from data_profiling.model.spark.typeset_spark import cast_frame

df = cast_frame(config, df, variables)
"""
# Java-style suffixes ("1.0d", "2f") are numbers to Spark, not to Python.
return F.when(value.rlike(r"[0-9.][dDfF]\s*$"), F.lit(None)).otherwise(
F.expr(f"try_cast({_quote(cleaned_name)} AS DOUBLE)")
Comment on lines +90 to +91
cleaned = f"__dp_number_{i}"
work = work.withColumn(cleaned, _cleaned_number(value))
column = _date(value)
elif is_string and target == "Boolean":
column = _boolean(value, config)
elif not is_string and target == "Categorical":
elif is_string and target == "Boolean":
column = _boolean(value, config)
elif not is_string and target == "Categorical":
column = value.cast("string")

This branch has not been deployed

No deployments
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.

2 participants