holdenk commented on code in PR #59722:
URL: https://github.com/apache/spark/pull/59722#discussion_r4585136027
##########
python/pyspark/sql/transpile.py:
##########
@@ -490,6 +496,16 @@ def _lower_eq(
"Python compares across types as unequal while Spark would
coerce "
"or fail analysis, so the transpiler falls back to
interpreted Python"
)
+ if lc in ("map", "array") or rc in ("map", "array"):
Review Comment:
Fixed in e31809b4768: the `_lower_eq` docstring now limits the
`None`-operand sentence to non-`map`/`array` categories and adds a paragraph
saying a `map` or `array` operand is always refused, `None` comparisons
included, because a map `=` fails analysis even against `None` and the `array`
category records neither the element type nor its collation.
---
<sub>🤖 Posted by an AI agent (Claude Code · skill `none`) on behalf of
@holdenk.</sub>
<!-- agent-attribution v1: agent=claude-code; skill=none; operator=holdenk
-->
##########
python/pyspark/sql/transpile.py:
##########
@@ -1126,15 +1150,29 @@ def _annotation_category(annotation: Optional[ast.AST])
-> Optional[str]:
"""Map a parameter's type annotation to a category, or ``None`` when absent
or unrecognised (the caller then tries all numeric and string variants).
- Returns one of ``"integer"``, ``"float"``, ``"string"``, ``"bool"``, or
- ``"binary"`` (matching the constant handling in ``_category``). ``int``
- maps to ``"integer"`` and ``float`` maps to ``"float"`` so the JVM can
- select the variant whose NaN semantics match the bound column type."""
+ Returns one of ``"integer"``, ``"float"``, ``"string"``, ``"bool"``,
+ ``"binary"``, ``"map"``, or ``"array"``. Numeric annotations select the
+ variant whose NaN semantics match the bound column type."""
+ if isinstance(annotation, ast.Subscript):
+ annotation = annotation.value # dict[str, str] -> dict
name: Optional[str] = None
if isinstance(annotation, ast.Name):
name = annotation.id
+ elif (
+ isinstance(annotation, ast.Attribute)
+ and isinstance(annotation.value, ast.Name)
+ and annotation.value.id == "typing"
+ ):
+ name = annotation.attr # typing.Dict -> Dict, but not torch.float
elif isinstance(annotation, ast.Constant) and isinstance(annotation.value,
str):
- name = annotation.value # stringized annotation, e.g. def f(a: "int")
+ # Parse quoted subscripted and typing-qualified forms like their
+ # unquoted spellings. Anything unparseable falls out as untyped.
+ try:
+ with _syntax_warnings_suppressed():
+ parsed = ast.parse(annotation.value, mode="eval").body
+ return _annotation_category(parsed)
+ except (SyntaxError, ValueError):
Review Comment:
Fixed in e31809b4768: added `('"the input value"', None)` to the cases in
`test_annotation_category_map_and_array`. I also checked it bites: with the
handler narrowed to `except ValueError`, the `SyntaxError` escapes
`_annotation_category`.
---
<sub>🤖 Posted by an AI agent (Claude Code · skill `none`) on behalf of
@holdenk.</sub>
<!-- agent-attribution v1: agent=claude-code; skill=none; operator=holdenk
-->
--
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]