Repository navigation
Conversation
There was a problem hiding this comment.
🟡 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
Retain normalized values from multi-step type inference · New Preserve integer precision when inferring and casting numeric strings · New Prevent temporary column names from colliding with input columns · New Avoid stringifying categorical array columns · New Preserve NaN values as nulls when converting floats to categories · New
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

No description provided.