itholic commented on a change in pull request #35191:
URL: https://github.com/apache/spark/pull/35191#discussion_r798208506
##########
File path: python/pyspark/pandas/series.py
##########
@@ -5228,22 +5228,128 @@ 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)
+
+ # e.g where = [10, 20]
+ # In the comments below , will explain how the dataframe will look
after transformations.
+ # e.g pd.Series([2, 1, np.nan, 4], index=[10, 20, 30, 40],
name="Koalas")
+
+ column_prefix_constant = "col_"
cond = [
- F.max(F.when(index_scol <= SF.lit(index).cast(index_type),
self.spark.column))
- for index in where
+ F.when(
+ index_scol <= SF.lit(index).cast(index_type),
+ F.struct(
+ F.lit(column_prefix_constant + str(index) + "_" +
str(idx)).alias("identifier"),
+ self.spark.column.alias("col_value"),
+ ),
+ ).alias(column_prefix_constant + str(index) + "_" + str(idx))
Review comment:
Can we make `column_prefix_constant + str(index) + "_" + str(idx)` as
variable and reuse here and there ??
##########
File path: python/pyspark/pandas/series.py
##########
@@ -5228,22 +5228,128 @@ 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)
+
+ # e.g where = [10, 20]
+ # In the comments below , will explain how the dataframe will look
after transformations.
+ # e.g pd.Series([2, 1, np.nan, 4], index=[10, 20, 30, 40],
name="Koalas")
+
+ column_prefix_constant = "col_"
cond = [
- F.max(F.when(index_scol <= SF.lit(index).cast(index_type),
self.spark.column))
- for index in where
+ F.when(
+ index_scol <= SF.lit(index).cast(index_type),
+ F.struct(
+ F.lit(column_prefix_constant + str(index) + "_" +
str(idx)).alias("identifier"),
+ self.spark.column.alias("col_value"),
+ ),
+ ).alias(column_prefix_constant + str(index) + "_" + str(idx))
Review comment:
I think we can simply use `F.last` with `ignorenulls=True` instead of
`F.max` ??
(https://spark.apache.org/docs/3.1.1/api/python/reference/api/pyspark.sql.functions.last.html)
e.g.
```python
cond = [
F.last(F.when(index_scol <= SF.lit(index).cast(index_type),
self.spark.column), ignorenulls=True)
for index in where
]
```
It returns the last non-null value from given column.
--
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]