You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/03/05 15:49:51 UTC

[GitHub] [spark] srowen commented on a change in pull request #11663: [SPARK-13068][PYSPARK][ML] Type conversion for Pyspark params

srowen commented on a change in pull request #11663: [SPARK-13068][PYSPARK][ML] Type conversion for Pyspark params
URL: https://github.com/apache/spark/pull/11663#discussion_r388382703
 
 

 ##########
 File path: python/pyspark/ml/param/__init__.py
 ##########
 @@ -65,6 +80,144 @@ def __eq__(self, other):
             return False
 
 
+class TypeConverters(object):
+    """
+    .. note:: DeveloperApi
+
+    Factory methods for common type conversion functions for `Param.typeConverter`.
+
+    .. versionadded:: 2.0.0
+    """
+
+    @staticmethod
+    def _is_numeric(value):
+        vtype = type(value)
+        return vtype in [int, float, np.float64, np.int64] or vtype.__name__ == 'long'
+
+    @staticmethod
+    def _is_integer(value):
+        return TypeConverters._is_numeric(value) and float(value).is_integer()
+
+    @staticmethod
+    def _can_convert_to_list(value):
+        vtype = type(value)
+        return vtype in [list, np.ndarray, tuple, xrange, array.array] or isinstance(value, Vector)
+
+    @staticmethod
+    def _can_convert_to_string(value):
 
 Review comment:
   @sethah @jkbradley sorry for a question on an old bit of code, but hope this is a quick one:
   These converters don't allow None. Some parameters can be set to None. Should they actually all just return None if their value is None? any harm in that?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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