-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-52394][PS] Fix autocorr divide-by-zero error under ANSI mode #51192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3396,11 +3396,14 @@ def autocorr(self, lag: int = 1) -> float: | |
else: | ||
lag_scol = F.lag(scol, lag).over(Window.orderBy(NATURAL_ORDER_COLUMN_NAME)) | ||
lag_col_name = verify_temp_column_name(sdf, "__autocorr_lag_tmp_col__") | ||
corr = ( | ||
sdf.withColumn(lag_col_name, lag_scol) | ||
.select(F.corr(scol, F.col(lag_col_name))) | ||
.head()[0] | ||
) | ||
|
||
sdf_lag = sdf.withColumn(lag_col_name, lag_scol) | ||
if is_ansi_mode_enabled(sdf.sparkSession): | ||
cov_value = sdf_lag.select(F.covar_samp(scol, F.col(lag_col_name))).first()[0] | ||
|
||
if cov_value is None or cov_value == 0.0: | ||
return np.nan | ||
corr = sdf_lag.select(F.corr(scol, F.col(lag_col_name))).head()[0] | ||
|
||
return np.nan if corr is None else corr | ||
|
||
def corr( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does
corr
affected by ansi?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example below shows how F.corr(col1, col2) fails with a DIVIDE_BY_ZERO error when ANSI on