HyukjinKwon commented on code in PR #37635:
URL: https://github.com/apache/spark/pull/37635#discussion_r959088633


##########
python/pyspark/sql/types.py:
##########
@@ -2268,12 +2268,40 @@ def convert(self, obj: "np.generic", gateway_client: 
GatewayClient) -> Any:
         return obj.item()
 
 
+class NumpyArrayConverter:
+    def can_convert(self, obj: Any) -> bool:
+        return has_numpy and isinstance(obj, np.ndarray)
+
+    def convert(self, obj: "np.ndarray", gateway_client: GatewayClient) -> 
JavaObject:
+        from pyspark import SparkContext
+
+        gateway = SparkContext._gateway
+        assert gateway is not None
+
+        plist = obj.tolist()
+        # np.array([]).dtype is dtype('float64') so set float for empty plist
+        ptpe = type(plist[0]) if len(plist) > 0 else float
+        tpe_dict = {
+            int: gateway.jvm.int,

Review Comment:
   Hm, unlike `obj.item` in which we have to pass Python primitive type; thus, 
resulting that JVM side type precision cannot be specified, here we can have 
more correct size in the JVM array.
   
   I think it's better to have the correct type in the element ... Ideally we 
should make `obj.item` respect the numpy dtype too..



-- 
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]

Reply via email to