Adding or changing an API
The end-to-end checklist for adding a functions / column / dataframe method (or changing an
existing one). It ties together the other guides; follow the links for detail.
1. Locate the right layer
- Implementation goes in the engine package under
sparkleframe/<engine>/(today:polarsdf). - Public modules (
functions.py,column.py,dataframe.py) are thin facades. Put shared or private logic in the matching*_helpers.py(functions_helpers.py,column_helpers.py,dataframe_helpers.py). See ARCHITECTURE.md for the layering.
2. Implement to Spark 4 semantics
- Match Spark 4.x behavior. Do not preserve Spark 3 semantics or pre–Spark 4 lenient defaults.
- For cast/parse/conversion, follow the strict/lenient pattern: one shared helper with a
strictflag; strict raises, lenient returnsnull. Never implement a strict API as a delegate to itstry_*sibling. See spark4-semantics.md. - Add type hints on all parameters and return types. Leave no dead code.
3. Write parity tests (valid AND malformed)
- Every new
functions/column/dataframemethod needs Spark parity tests in the matching*_test.py, asserting against real PySpark withassert_matches_spark. - Fixtures must include malformed / edge-case inputs, not just well-formed data — otherwise
strict error paths never run. For strict/lenient pairs, cover both the raising and the
null-returning sides. Full patterns and the
enginefixture vsENGINES[Engine.POLARS]choice are in testing.md.
4. Update the gate if you promoted a behavior
- If a parity test now passes on an engine that previously gated it, delete its
@pytest.mark.featureid from that engine's set ingaps.pyand lowerPYTHON_GATE_HIGH_WATER_MARKaccordingly — in the same commit. See engines.md. - If you changed Polars behavior that's documented in ../known_gaps.md, update that doc too.
5. Verify — Definition of Done
Run everything in Docker (the container provides env the Spark fixture needs):
make black # format
make lint # ruff
make test f=<the test file(s) you touched> # fast inner loop
make pr-check # black + lint + coverage — the gate
A change is done when:
- [ ] Logic lives in the right layer (facade thin, helper holds the logic).
- [ ] Spark 4 semantics; strict/lenient via a shared
strictflag, notry_*delegation. - [ ] Parity tests cover valid and malformed inputs and pass against real Spark.
- [ ]
gaps.pyandPYTHON_GATE_HIGH_WATER_MARKupdated if a behavior was promoted;known_gaps.mdupdated if a documented Polars gap changed. - [ ]
make pr-checkis green. - [ ] Type hints present; no dead code; docs touched if behavior/coverage changed.