Skip to content

[SPARK-54986][DOCS] Document return types for aggregate functions#55083

Open
piyushka-ally wants to merge 1 commit intoapache:masterfrom
piyushka-ally:SPARK-54986-doc-aggregate-return-types
Open

[SPARK-54986][DOCS] Document return types for aggregate functions#55083
piyushka-ally wants to merge 1 commit intoapache:masterfrom
piyushka-ally:SPARK-54986-doc-aggregate-return-types

Conversation

@piyushka-ally
Copy link
Copy Markdown

What changes were proposed in this pull request?

Added Notes sections to PySpark docstrings for 15 aggregate functions in python/pyspark/sql/functions/builtin.py, documenting their return data types:

  • Always DoubleType: stddev, std, stddev_samp, stddev_pop, variance, var_samp, var_pop, skewness, kurtosis, corr, covar_pop, covar_samp
  • Input-dependent: avg/mean (DoubleType for numeric, DecimalType for decimal, interval type for interval inputs) and sum (LongType for integral, DecimalType for decimal, DoubleType for other numeric, interval type for interval inputs)

The return type information was confirmed from the Scala implementations: CentralMomentAgg, Average, Sum, PearsonCorrelation, and Covariance in sql/catalyst/.../expressions/aggregate/.

The Notes section style follows the existing pattern used by max and min in 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 like stddev always return DoubleType regardless of input type, or that sum returns LongType for 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 Notes sections (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

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
@piyushka-ally piyushka-ally force-pushed the SPARK-54986-doc-aggregate-return-types branch from 5194514 to 6de8c2f Compare March 30, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant