spark-test commented on code in PR #58185:
URL: https://github.com/apache/spark/pull/58185#discussion_r4508573437
##########
python/pyspark/sql/transpile.py:
##########
@@ -816,20 +866,23 @@ def _get_transpilers(session: "SparkSession") ->
List[AbstractTranspiler]:
def _annotation_category(annotation: Optional[ast.AST]) -> Optional[str]:
"""Map a parameter's type annotation to a category
- (``"numeric"``/``"string"``/``"bool"``/``"binary"``), or ``None`` when it's
- absent or unrecognised (the caller then tries both numeric and string)."""
+ (``"integral"``/``"fractional"``/``"string"``/``"bool"``/``"binary"``), or
+ ``None`` when it's absent or unrecognised (the caller then tries the
applicable
+ numeric and string categories)."""
name: Optional[str] = None
if isinstance(annotation, ast.Name):
name = annotation.id
elif isinstance(annotation, ast.Constant) and isinstance(annotation.value,
str):
name = annotation.value # stringized annotation, e.g. def f(a: "int")
- # str -> "string", int/float -> "numeric", bool -> "bool", bytes ->
"binary"
- # (matching the constant handling in ``_category``). complex and anything
- # unrecognised return None so the caller tries both numeric and string.
+ # Match int and float separately so comparisons can omit NaN checks for
integral
+ # inputs. complex and anything unrecognised return None so the caller
tries all
+ # applicable numeric and string categories.
if name == "str":
return "string"
- if name in ("int", "float"):
- return "numeric"
+ if name == "int":
Review Comment:
**Non-blocking (P2):** This now pins `int` to `integral` and `float` to
`fractional` in every function, not only in functions with a value comparison,
and `ResolveTranspiledPythonUDFOptions` accepts those only for IntegralType and
FloatType/DoubleType. At the base branch both annotations mapped to `numeric`,
which matched any non-decimal numeric column. So `def f(x: float): return x *
2.0` on a long column, a normal call under PEP 484's numeric tower, now loses
its only option and runs as an interpreted Python UDF, and `def f(x: int):
return x + 1` on a double column does the same. Neither body compares anything,
so there is no NaN check to protect, and the module docstring recommends
annotating. Results are unchanged; the cost is the Python fallback.
This extends an [existing
discussion](https://github.com/apache/spark/pull/58185#issuecomment-5704479487).
See **Shared repair plan 1** in the review body.
--
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]