Merged
Conversation
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.
Make PySpark an optional dependency
Closes #54
Users running PySpark in managed environments (Databricks, EMR, etc.) typically have PySpark
pre-installed and cannot or do not want the library to reinstall it. Previously,
pysparkwasa hard dependency, making
dataframe-expectationsincompatible with those environments.This PR makes PySpark fully optional while preserving all existing behaviour for users who do
have it installed.
What changed
1. PySpark moved to an optional extra (
pyproject.toml)pandas,pydantic, andtabulateremain hard dependencies.pysparkis now under[project.optional-dependencies].2. Lazy PySpark loading in production code (
pyspark_utils.py)All PySpark imports are deferred behind
@lru_cachehelpers:get_pyspark_functions()— returns realpyspark.sql.functionswhen PySpark is available,or a
_MissingPySparkFunctionsproxy that raises a clearImportErroronly when a PySparkcode path is actually executed.
_get_pyspark_dataframe_types()/is_pyspark_dataframe()— runtime type detection withgraceful fallback when PySpark is absent.
PySparkConnectDataFrameinexpectation.py) isguarded with
try/except ImportErrorand is kept for backward compatibility and test patching.This means importing
dataframe_expectationsnever touches PySpark at all when it isn't installed.3. Tests split by marker
All PySpark test cases are decorated with
@pytest.mark.pysparkand separated into their ownparametrize blocks.
--strict-markersis enforced inpyproject.tomlso unregistered markerscause an immediate failure rather than being silently ignored. Tests can now be run without
PySpark present:
4. CI updated to cover three install scenarios
tests-without-pyspark-m "not pyspark"tests-with-pyspark-extrapip install .[pyspark]tests-with-external-pysparkThe external-pyspark job specifically validates the case from issue #54 — that the library works
correctly when PySpark is already present in the environment and was not installed by this package.
5. Docs updated
Installation instructions updated to document both install paths and explain when each is appropriate.
Checklist