Yikun commented on a change in pull request #35191:
URL: https://github.com/apache/spark/pull/35191#discussion_r784446470



##########
File path: python/pyspark/pandas/series.py
##########
@@ -5228,22 +5228,62 @@ def asof(self, where: Union[Any, List]) -> 
Union[Scalar, "Series"]:
             where = [where]
         index_scol = self._internal.index_spark_columns[0]
         index_type = self._internal.spark_type_for(index_scol)
+        from pyspark.sql.functions import struct, lit, explode, col, row_number
+
+        column_prefix_constant = "col_"
         cond = [
-            F.max(F.when(index_scol <= SF.lit(index).cast(index_type), 
self.spark.column))
+            F.when(
+                index_scol <= SF.lit(index).cast(index_type),
+                struct(
+                    lit(column_prefix_constant + 
str(index)).alias("identifier"),
+                    self.spark.column.alias("Koalas"),
+                ),
+            ).alias(column_prefix_constant + str(index))
             for index in where
         ]
+        cond.append(index_scol)
         sdf = self._internal.spark_frame.select(cond)
+        columns = [cols for cols in sdf.columns if cols.startswith("col")]
+        sdf = sdf.withColumn("combined_cols", F.array(columns)).drop(*columns)
+        sdf = (
+            sdf.select(index_scol, explode("combined_cols").alias("values"))
+            .withColumn("identifier", col("values.identifier"))
+            .withColumn("value", col("values.Koalas"))
+            .drop("values")
+            .na.drop(subset="value")

Review comment:
       BTW, there was [a complain in lint 
CI](https://github.com/pralabhkumar/spark/runs/4801311278?check_suite_focus=true#step:15:23),
 it should be a bug on type hint of `na.drop`, I submit the fixed on [1].
   
   You could just use `dropna(subset="value")` instead of 
`.na.drop(subset="value")` to work around.
   
   [1] https://github.com/apache/spark/pull/35201




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