HyukjinKwon opened a new pull request, #901:
URL: https://github.com/apache/spark-connect-rust/pull/901
### What changes were proposed in this pull request?
A sweep compared the docstrings of pyspark-client 4.3.0 and of the drop-in
by their exact text, on master 32b27eb6 (SPARK-62115, #899). It covered the
modules of `pyspark.sql` and `pyspark.errors` that both import, 124 of them:
each module, each public class and function that it defines, and each public
member of such a class, as Python finds it on the class. As the golden compares
them, an object counts as the same if its `__doc__` is the same. Where
PySpark's object has no docstring of its own and inherits one, it counts as the
same if its `inspect.getdoc` is the same. Of 5548 objects of PySpark:
| | Same | Differ | Missing in the drop-in |
|---|---|---|---|
| Before, master 32b27eb6 | 4436 | 126 | 986 |
| After, this PR | 4478 | 84 | 986 |
`pyspark.sql.connect.session` went from 0 / 43 / 0 to 42 / 1 / 0 (same /
differ / missing). With the 9 members of the classes of the SparkSession's
body, which the golden now compares too, this PR makes 51 docstrings PySpark's:
- the module's;
- the `SparkSession` class and 40 of its members, its `Builder` and its
`Hook` among them;
- the 8 members of the `Builder` (`appName`, `channelBuilder`, `config`,
`create`, `enableHiveSupport`, `getOrCreate`, `master`, `remote`);
- `on_execute_plan` of the `Hook`.
The one left is the `__init__` of the native `SparkSession`, CPython's slot
(below).
**Why they differed.** PySpark Connect's `SparkSession` is a class of its
own, not a subclass of the classic one.
- Its module copies the classic SparkSession's docstrings onto its class and
32 of its members (`sql.__doc__ = PySparkSession.sql.__doc__`).
- Its other members, its `Builder` and its `Hook` have docstrings of their
own (`stop`, `newSession`, `cloneSession`, `channelBuilder`, ...).
- Some have none:
- `active` and `getActiveSession`, classmethods, whose assigned docstrings
are of the classmethod wrappers, not of the functions that the class gives;
- `session_id`;
- the `Builder`'s `appName`, `config`, `create`, `enableHiveSupport`,
`getOrCreate`, `master` and `remote`.
The drop-in's `SparkSession`, `Builder` and `Hook` are native, and their
docstrings were their own doc comments.
**The changes:**
- **The generator covers the session.** `gen_connect_docstrings.py`
generates the docstrings of `pyspark.sql.connect.session` too
(`CLASS_MODULES`): of its classes, of the classes of their bodies
(`SparkSession.Builder`, `SparkSession.Hook`), and of their public members, as
Python finds them on each class.
- The generated docstrings are exactly what pyspark-client has at run
time, for all 54 objects of the module.
- The string arms of the classes, which only the types' `abstract_type!`
forwards, stay of `pyspark.sql.types` alone (`NAMED_CLASS_MODULES`).
- **The native classes take them.** The native `SparkSession`, `Builder` and
`Hook` of `session.rs` take 39 `#[doc = connect_doc!(...)]` attributes.
- Their doc comments are now plain comments: 161 lines change only by a
slash, and no code moves.
- The members of no docstring in PySpark have none.
- **The module has no docstring, as PySpark's.** That is
`connect/session.py`; its former text stays as a comment.
- **The golden covers the session.**
- `python/tests/_runtime_docstrings.py` takes the members of the public
classes of a class's body too (`SparkSession.Builder.getOrCreate`), and leaves
out only `pyspark.sql.connect.client`.
- `tests/golden/runtime_docstrings.json` now holds 5477 docstrings of 126
modules, up from 5387 of 125. 799 of them are of the `getdoc` kind.
- The new entries of the classes of class bodies in other modules were
PySpark's already: the clauses of the `MergeIntoWriter` (classic and Connect),
`CollectedMetrics.Node`, the classic `SparkSession.Builder`, and the `Java`
classes of `JStreamingQueryListener` and `ForeachBatchFunction`.
- `test_the_docstrings_of_the_modules_are_pysparks` now compares 4323
docstrings, and asserts at least 4300, up from 4000.
- **Docs:**
- `dev/parity/known-differences.md` names the `__init__` of the
SparkSession among those of the native classes;
- `docs/compatibility.md` lists the SparkSession and its Builder and Hook
among the classes of PySpark's docstrings, and says that the golden leaves out
only the client of the session.
**What remains** of the 84 that differ:
- **Inherent, 4:** the `__init__` of the `SparkSession`, the `DataFrame`,
the `RuntimeConf` and the `Observation` of Spark Connect, which have docstrings
in PySpark Connect (their own, or copies). A native class's `__init__` is
CPython's slot, which keeps CPython's docstring.
- **Of other work, left out of the golden:** `pyspark.sql.connect.client`
and `client.core` (80, and 6 of the missing names), after the move of
`client.core`.
The 986 missing names are as before.
### Why are the changes needed?
So that `help()` and the other tools that read docstrings show PySpark's
documentation for the SparkSession of Spark Connect, its Builder and its Hook,
as with pyspark-client, and so that the golden guards them.
### Does this PR introduce _any_ user-facing change?
Yes:
- The `__doc__` of the SparkSession of Spark Connect, of its Builder and its
Hook, and of their members is PySpark's, as with pyspark-client: the classic
SparkSession's where PySpark Connect copies them, PySpark Connect's own, or
none.
- The module docstring of `pyspark.sql.connect.session` is None.
### How was this patch tested?
- **The golden test**, `test_the_docstrings_of_the_modules_are_pysparks` of
`test_dropin_class_modules_offline.py`, with the new golden:
- on master 32b27eb6, 51 of 4323 differ, the 51 above;
- on this branch, none.
The golden reproduces when captured again with pyspark-client.
`test_dropin_class_modules_offline.py` gives 260 passed; on master, 1 failed
(this test) and 259 passed.
- **A probe of both clients:** the docstrings of the 54 objects of the
SparkSession, its Builder and its Hook are PySpark's, by their kinds, but the 3
`__init__` slots. The `inspect.signature` and `__text_signature__` of the 53
classes and members of the three are those of master.
- **The sweep of both clients**, before and after, in the table above.
- **The gates:**
- `cargo fmt --all --check`;
- `cargo +1.100.0 clippy -p apache-spark-connect-core -p
apache-spark-connect -p pyspark-rs --all-targets -- -D warnings`;
- `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p apache-spark-connect
-p apache-spark-connect-core`;
- `cargo test -p pyspark-rs --lib`: 17 passed;
- `gen_connect_docstrings.py --check` (both files), `gen_type_stubs.py
--check`, `gen_fn_dispatch.py --check`, `check_classic_bindings.py`;
- ruff 0.14.0, the no-stub audit, the guards and
`test_type_stubs_offline.py` with pyright 1.1.414 (18 passed);
- the offline suite of `coverage.yml`: 6912 passed, 77 skipped;
- `test_dropin_e2e.py`, the tests of the session, its builder, its conf,
catalog, tags, interrupts, artifacts, progress handlers, SQL and ranges (`-k
"session or builder or conf or catalog or interrupt or tag or artifact or
progress or active or stop or clone or newSession or sql or range or
createDataFrame or table or doc"`), against a Spark 4.3.0 server: 72 passed.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
This pull request and its description were written by Isaac.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]