HyukjinKwon opened a new pull request, #555:
URL: https://github.com/apache/spark-connect-rust/pull/555
### What changes were proposed in this pull request?
The `createDataFrame` errors of the Python client that name the type of a
value now name it as PyArrow does. PyArrow formats the type's `tp_name`: the
bare name of a class defined in Python (a heap type), and the module-qualified
name of a builtin or C type. `arrow_type_name`
(`crates/pyspark-rs/src/infer.rs`) now returns the bare `__name__` for a heap
type and keeps the module-qualified name for a static type. The same helper
produces both the "was not a sequence or recognized null for conversion to list
type" message and the "Expected bytes, got a '...' object" message.
The comment of `test_freed_instances_release_their_dict_as_pyspark` no
longer claims that `vars()` of a `Column` is PySpark's. Ours holds only the
attributes that were set; PySpark's also holds `_expr`.
### Why are the changes needed?
```python
class DictSub(dict): pass
spark.createDataFrame([(DictSub({1: 2}),)], "a array<int>")
# before: ArrowTypeError: Could not convert {1: 2} with type
__main__.DictSub: was not a sequence ...
# after (and PySpark 4.3.0 with pyarrow 26.0.1): ... with type DictSub: was
not a sequence ...
spark.createDataFrame([(collections.Counter(),)], "a array<int>")
# before: ... with type collections.Counter ... after (and PySpark): ...
with type Counter ...
```
Builtin and C types (`dict`, `collections.OrderedDict`) were already named
as PyArrow names them, and are unchanged. This is a follow-up of SPARK-61483
(#538).
### Does this PR introduce _any_ user-facing change?
Yes, in error messages only. The type name in these two `createDataFrame`
errors is the bare class name for a class defined in Python, as in PySpark.
### How was this patch tested?
- A new offline test,
`test_pyarrow_names_a_type_by_its_tp_name_in_its_errors`, covers a dict
subclass, a `Counter`, a frozenset subclass, `OrderedDict` and `dict`, for both
messages. Its three heap-type cases fail without the fix and pass with it. The
messages were checked against PySpark 4.3.0.
- The offline suite (1907 passed), the e2e suites against a Spark 4.3.0
server (`test_arrow_e2e.py`, `test_dropin_e2e.py`, `test_ml_e2e.py`: 303
passed), the Rust library tests, the `--no-run` builds (with and without
`wasm-udf`), `cargo fmt --check`, `scripts/audit_no_stubs.sh` and the ruff
gates.
### 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]