[SPARK-54986][DOCS] Document return types for aggregate functions#55083
Open
piyushka-ally wants to merge 1 commit intoapache:masterfrom
Open
[SPARK-54986][DOCS] Document return types for aggregate functions#55083piyushka-ally wants to merge 1 commit intoapache:masterfrom
piyushka-ally wants to merge 1 commit intoapache:masterfrom
Conversation
Add Notes sections to PySpark docstrings for aggregate functions documenting their return data types, which were previously undocumented. - stddev, std, stddev_samp, stddev_pop, variance, var_samp, var_pop, skewness, kurtosis, corr, covar_pop, covar_samp: always DoubleType - avg, mean: DoubleType for numerics, DecimalType for decimals, interval type for intervals - sum: LongType for integrals, DecimalType for decimals, DoubleType for other numerics, interval type for intervals Closes apache#54986 Co-authored-by: Isaac
5194514 to
6de8c2f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Added
Notessections to PySpark docstrings for 15 aggregate functions inpython/pyspark/sql/functions/builtin.py, documenting their return data types:DoubleType:stddev,std,stddev_samp,stddev_pop,variance,var_samp,var_pop,skewness,kurtosis,corr,covar_pop,covar_sampavg/mean(DoubleTypefor numeric,DecimalTypefor decimal, interval type for interval inputs) andsum(LongTypefor integral,DecimalTypefor decimal,DoubleTypefor other numeric, interval type for interval inputs)The return type information was confirmed from the Scala implementations:
CentralMomentAgg,Average,Sum,PearsonCorrelation, andCovarianceinsql/catalyst/.../expressions/aggregate/.The
Notessection style follows the existing pattern used bymaxandminin the same file, which already document null/NaN handling behavior.Why are the changes needed?
The PySpark API docs for these aggregate functions don't document their return data types. Users have to read the Scala source code (e.g.,
CentralMomentAgg.scala) to discover that functions likestddevalways returnDoubleTyperegardless of input type, or thatsumreturnsLongTypefor integer inputs. This information should be readily available in the Python docstrings.See: #54986
Does this PR introduce any user-facing change?
No. This is a documentation-only change.
How was this patch tested?
Documentation-only change. Verified that all docstrings follow valid NumPy-style RST formatting consistent with existing
Notessections (e.g.,max,min) in the same file. Return type claims were cross-checked against the Scala source implementations.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (claude.ai/code) using Claude Opus 4.6