xinrong-databricks commented on a change in pull request #33466:
URL: https://github.com/apache/spark/pull/33466#discussion_r677860488



##########
File path: python/pyspark/pandas/data_type_ops/num_ops.py
##########
@@ -395,6 +401,17 @@ def restore(self, col: pd.Series) -> pd.Series:
         """Restore column when to_pandas."""
         return col.astype(self.dtype)
 
+    def astype(self, index_ops: IndexOpsLike, dtype: Union[str, type, Dtype]) 
-> IndexOpsLike:
+        dtype, spark_type = pandas_on_spark_type(dtype)
+        if index_ops.hasnans:
+            if is_integer_dtype(dtype) and not isinstance(dtype, 
extension_dtypes):
+                raise ValueError(
+                    "Cannot convert %s with missing values to integer" % 
self.pretty_name
+                )
+            elif is_bool_dtype(dtype) and not isinstance(dtype, 
extension_dtypes):
+                raise ValueError("Cannot convert %s with missing values to 
bool" % self.pretty_name)

Review comment:
       Good idea! Updated.

##########
File path: python/pyspark/pandas/data_type_ops/num_ops.py
##########
@@ -318,6 +324,13 @@ def isnull(self, index_ops: IndexOpsLike) -> IndexOpsLike:
 
     def astype(self, index_ops: IndexOpsLike, dtype: Union[str, type, Dtype]) 
-> IndexOpsLike:
         dtype, spark_type = pandas_on_spark_type(dtype)
+        if index_ops.hasnans:
+            if is_integer_dtype(dtype) and not isinstance(dtype, 
extension_dtypes):
+                raise ValueError(
+                    "Cannot convert %s with missing values to integer" % 
self.pretty_name
+                )
+            elif is_bool_dtype(dtype) and not isinstance(dtype, 
extension_dtypes):
+                raise ValueError("Cannot convert %s with missing values to 
bool" % self.pretty_name)

Review comment:
       Updated.




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