ueshin commented on a change in pull request #33877:
URL: https://github.com/apache/spark/pull/33877#discussion_r702168125



##########
File path: python/pyspark/pandas/data_type_ops/base.py
##########
@@ -184,10 +186,21 @@ def _as_other_type(
     )
     assert not need_pre_process, "Pre-processing is needed before the type 
casting."
 
-    scol = index_ops.spark.column.cast(spark_type)
+    if isinstance(index_ops.spark.data_type, TimestampNTZType) and isinstance(
+        spark_type, NumericType
+    ):
+        scol = 
_cast_spark_column_timestamp_ntz_to_long(index_ops.spark.column).cast(spark_type)
+    else:
+        scol = index_ops.spark.column.cast(spark_type)

Review comment:
       We shouldn't put `index_ops`'s data type dependent code here but in 
`DatetimeOps.astype` instead?

##########
File path: python/pyspark/pandas/data_type_ops/base.py
##########
@@ -184,10 +186,21 @@ def _as_other_type(
     )
     assert not need_pre_process, "Pre-processing is needed before the type 
casting."
 
-    scol = index_ops.spark.column.cast(spark_type)
+    if isinstance(index_ops.spark.data_type, TimestampNTZType) and isinstance(
+        spark_type, NumericType
+    ):
+        scol = 
_cast_spark_column_timestamp_ntz_to_long(index_ops.spark.column).cast(spark_type)
+    else:
+        scol = index_ops.spark.column.cast(spark_type)
+
     return index_ops._with_new_scol(scol, field=InternalField(dtype=dtype))
 
 
+def _cast_spark_column_timestamp_ntz_to_long(scol: Column) -> Column:
+    jvm = SparkContext._active_spark_context._jvm  # type: ignore
+    return Column(jvm.PythonSQLUtils.unixSecondsUTC(scol._jc))

Review comment:
       This should be placed in `.../data_type_ops/datetime_ops.py`?




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