zhengruifeng opened a new pull request, #37975:
URL: https://github.com/apache/spark/pull/37975
### What changes were proposed in this pull request?
add a new `var` expression to support arbitary integeral `ddof`
### Why are the changes needed?
for API coverage
### Does this PR introduce _any_ user-facing change?
yes, it accept `ddof` other than {0, 1}
before
```
In [1]: import pyspark.pandas as ps
In [2]: import numpy as np
In [3]: df = ps.DataFrame({'a': [1, 2, 3, np.nan], 'b': [0.1, 0.2, 0.3,
np.nan]}, columns=['a', 'b'])
In [4]: df.var(ddof=2)
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
Cell In [4], line 1
----> 1 df.var(ddof=2)
File ~/Dev/spark/python/pyspark/pandas/generic.py:1958, in Frame.var(self,
axis, ddof, numeric_only)
1904 def var(
1905 self, axis: Optional[Axis] = None, ddof: int = 1, numeric_only:
bool = None
1906 ) -> Union[Scalar, "Series"]:
1907 """
1908 Return unbiased variance.
1909
(...)
1956 0.6666666666666666
1957 """
-> 1958 assert ddof in (0, 1)
1960 axis = validate_axis(axis)
1962 if numeric_only is None and axis == 0:
AssertionError:
```
after
```
In [4]: df.var(ddof=2)
Out[4]:
a 2.00
b 0.02
dtype: float64
In [5]: df.to_pandas().var(ddof=2)
/Users/ruifeng.zheng/Dev/spark/python/pyspark/pandas/utils.py:975:
PandasAPIOnSparkAdviceWarning: `to_pandas` loads all data into the driver's
memory. It should only be used if the resulting pandas DataFrame is expected to
be small.
warnings.warn(message, PandasAPIOnSparkAdviceWarning)
Out[5]:
a 2.00
b 0.02
dtype: float64
```
### How was this patch tested?
added UT
--
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]