zero323 commented on a change in pull request #34226:
URL: https://github.com/apache/spark/pull/34226#discussion_r726594019
##########
File path: python/pyspark/sql/column.py
##########
@@ -71,30 +97,37 @@ def _to_list(sc, cols, converter=None):
"""
if converter:
cols = [converter(c) for c in cols]
- return sc._jvm.PythonUtils.toList(cols)
+ return sc._jvm.PythonUtils.toList(cols) # type: ignore[attr-defined]
-def _unary_op(name, doc="unary operator"):
+def _unary_op(
+ name: str,
+ doc: str = "unary operator",
+) -> Callable[["Column"], "Column"]:
""" Create a method for given unary operator """
- def _(self):
+ def _(self: "Column") -> "Column":
jc = getattr(self._jc, name)()
return Column(jc)
_.__doc__ = doc
return _
-def _func_op(name, doc=''):
- def _(self):
- sc = SparkContext._active_spark_context
+def _func_op(name: str, doc: str = '') -> Callable[["Column"], "Column"]:
+ def _(self: "Column") -> "Column":
+ sc = SparkContext._active_spark_context # type: ignore[attr-defined]
jc = getattr(sc._jvm.functions, name)(self._jc)
return Column(jc)
_.__doc__ = doc
return _
-def _bin_func_op(name, reverse=False, doc="binary function"):
- def _(self, other):
- sc = SparkContext._active_spark_context
+def _bin_func_op(
+ name: str,
+ reverse: bool = False,
+ doc: str = "binary function",
+) -> Callable[["Column", Union["Column", "LiteralType", "DecimalLiteral"]],
"Column"]:
+ def _(self: "Column", other: Union["Column", "LiteralType",
"DecimalLiteral"]) -> "Column":
Review comment:
The first argument for returned `Callable` can literal if `reverse` is
`False`. In fact, it is the case for both functions where we use it. Should we
overload it with `Literal`?
```
>>> lit(4) ** 2
Column<'POWER(4, 2)'>
>>> 2 ** lit(4)
Column<'POWER(2, 4)'>
>>> lit(4) ** lit(2)
Column<'POWER(4, 2)'>
```
--
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]