itholic commented on a change in pull request #35191:
URL: https://github.com/apache/spark/pull/35191#discussion_r801233985
##########
File path: python/pyspark/pandas/tests/test_series.py
##########
@@ -2071,6 +2071,22 @@ def test_asof(self):
with ps.option_context("compute.eager_check", False):
self.assert_eq(psser.asof(20), 4.0)
+ pser = pd.Series([2, 1, np.nan, 4], index=[10, 20, 30, 40],
name="Koalas")
+ psser = ps.from_pandas(pser)
+ self.assert_eq(psser.asof([5, 20]), pser.asof([5, 20]))
+
+ pser = pd.Series([4, np.nan, np.nan, 2], index=[10, 20, 30, 40],
name="Koalas")
+ psser = ps.from_pandas(pser)
+ self.assert_eq(psser.asof([5, 100]), pser.asof([5, 100]))
+
+ pser = pd.Series([np.nan, 4, 1, 2], index=[10, 20, 30, 40],
name="Koalas")
+ psser = ps.from_pandas(pser)
+ self.assert_eq(psser.asof([5, 35]), pser.asof([5, 35]))
+
+ pser = pd.Series([2, 1, np.nan, 4], index=[10, 20, 30, 40],
name="Koalas")
+ psser = ps.from_pandas(pser)
+ self.assert_eq(psser.asof([25, 25]), pser.asof([25, 25]))
Review comment:
Can we also test the string & timestamp index ??
e.g.
```python
>>> pser = pd.Series([2, 1, np.nan, 4], index=['a', 'b', 'c', 'd'])
>>> pser.asof(['a', 'd'])
a 2.0
d 4.0
dtype: float64
```
```python
>>> pser = pd.Series([2, 1, np.nan, 4], index=[pd.Timestamp(2020, 1, 1),
pd.Timestamp(2020, 2, 2), pd.Timestamp(2020, 3, 3), pd.Timestamp(2020, 4, 4)])
>>> pser.asof([pd.Timestamp(2020, 1, 1), pd.Timestamp(2020, 2, 4)])
2020-01-01 2.0
2020-02-04 1.0
dtype: float64
```
##########
File path: python/pyspark/pandas/tests/test_series.py
##########
@@ -2071,6 +2071,22 @@ def test_asof(self):
with ps.option_context("compute.eager_check", False):
self.assert_eq(psser.asof(20), 4.0)
+ pser = pd.Series([2, 1, np.nan, 4], index=[10, 20, 30, 40],
name="Koalas")
+ psser = ps.from_pandas(pser)
+ self.assert_eq(psser.asof([5, 20]), pser.asof([5, 20]))
+
+ pser = pd.Series([4, np.nan, np.nan, 2], index=[10, 20, 30, 40],
name="Koalas")
+ psser = ps.from_pandas(pser)
+ self.assert_eq(psser.asof([5, 100]), pser.asof([5, 100]))
+
+ pser = pd.Series([np.nan, 4, 1, 2], index=[10, 20, 30, 40],
name="Koalas")
+ psser = ps.from_pandas(pser)
+ self.assert_eq(psser.asof([5, 35]), pser.asof([5, 35]))
+
+ pser = pd.Series([2, 1, np.nan, 4], index=[10, 20, 30, 40],
name="Koalas")
+ psser = ps.from_pandas(pser)
+ self.assert_eq(psser.asof([25, 25]), pser.asof([25, 25]))
Review comment:
And also set the `np.nan` as `where` ?
```python
>>> pser.asof([np.nan, np.nan])
NaN 3.0
NaN 3.0
dtype: float64
```
Seems like this case is only supported for numeric type index.
--
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]