dbtsai commented on code in PR #127:
URL:
https://github.com/apache/spark-connect-rust/pull/127#discussion_r4433559513
##########
python/tests/test_dropin_offline.py:
##########
@@ -3085,3 +3085,162 @@ def allow_response_after_request():
else:
assert result == [("id", "bigint")]
assert service.calls == 1
+
+
+# Exact built-in string conversion and full outbound Arrow IPC guards.
+
+
[email protected]("text", [
+ "", "1.25", "-42", "NaN", "a\x00b", "é雪😀", "e\u0301", "\uffff",
+])
+def test_exact_string_roundtrip(text):
+ actual = Row(value=text).value
+ assert type(actual) is str
+ assert actual == text
+
+
[email protected]("text", ["\ud800", "\udfff", "a\ud800b"])
+def test_exact_string_surrogate_error_preserves_generic_fallback(text):
+ with pytest.raises(TypeError):
+ Row(value=text)
+
+
+def test_exact_string_subclass_protocol_order():
Review Comment:
Reduced this to one `__index__` subclass that converts to `17`, guarding
`cast_exact`. Treating `str` subclasses, including `numpy.str_`, as text
changes the existing numeric protocol behavior, so I agree it should be a
separate parity change; this PR keeps current behavior.
##########
crates/pyspark-rs/src/session.rs:
##########
@@ -955,6 +955,14 @@ pub(crate) fn py_to_value(obj: &Bound<'_, PyAny>) ->
PyResult<Value> {
return Ok(Value::Null);
}
+ // Exact built-in strings cannot implement numeric conversion protocols.
+ // Keep subclasses and strings that fail UTF-8 extraction on the generic
path.
+ if let Ok(s) = obj.cast_exact::<pyo3::types::PyString>() {
+ if let Ok(s) = s.extract::<String>() {
Review Comment:
Agreed that preserving the extraction error would be clearer. I left the
existing TypeError fallback unchanged to keep this optimization
behavior-preserving; the surrogate cases check that compatibility. Propagating
the original Unicode error can be a separate behavior change.
--
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]