zero323 commented on a change in pull request #35136:
URL: https://github.com/apache/spark/pull/35136#discussion_r780382158



##########
File path: python/pyspark/ml/param/__init__.py
##########
@@ -76,33 +99,33 @@ class TypeConverters:
     """
 
     @staticmethod
-    def _is_numeric(value):
+    def _is_numeric(value: Any) -> bool:
         vtype = type(value)
         return vtype in [int, float, np.float64, np.int64] or vtype.__name__ 
== "long"
 
     @staticmethod
-    def _is_integer(value):
+    def _is_integer(value: Any) -> bool:
         return TypeConverters._is_numeric(value) and float(value).is_integer()
 
     @staticmethod
-    def _can_convert_to_list(value):
+    def _can_convert_to_list(value: Any) -> bool:
         vtype = type(value)
         return vtype in [list, np.ndarray, tuple, range, array.array] or 
isinstance(value, Vector)
 
     @staticmethod
-    def _can_convert_to_string(value):
+    def _can_convert_to_string(value: Any) -> bool:
         vtype = type(value)
         return isinstance(value, str) or vtype in [np.unicode_, np.string_, 
np.str_]
 
     @staticmethod
-    def identity(value):
+    def identity(value: "T") -> "T":
         """
         Dummy converter that just returns value.
         """
         return value
 
     @staticmethod
-    def toList(value):
+    def toList(value: Any) -> List:

Review comment:
       This and other `to*` methods could be more precise with specific 
overloads, i.e.
   
   ```python
       @staticmethod
       @overload
       def toList(value: List[T]) -> List[T]:
           ...
   
       @staticmethod
       @overload
       def toList(value: range) -> List[int]:
           ...
   
       @staticmethod
       @overload
       def toList(value: Vector) -> List[float]:
           ...
   
   ```
   
   and so on, but it is probably not worth the effort.




-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to