Skip to content

[Bug]: DataFrame API skew() and kurtosis() raise UnboundLocalError when all the data is in one partition #41283

Open

Description

@sohailshk

What happened?

On master (d7d31e9), Series.skew() and Series.kurtosis() / kurt() in the DataFrame API (also reached through DataFrame.skew(), DataFrame.kurt() and agg('skew')) fail with UnboundLocalError: cannot access local variable 'combined_n' where it is not associated with a value when one partition holds all the values. combine_moments in dataframe/frames.py assigns combined_n only when it merges two non-empty partitions, but the final formula always reads it.

Example: to_dataframe(p | beam.Create([beam.Row(x=float(i * i)) for i in range(6)])).x.skew() fails on the default runner and on the FnApiRunner; pandas returns 0.9191843544212499 (skew) and -0.25414322711619963 (kurtosis) for the same values. With fewer than 3 values (skew) or 4 (kurtosis), or with all-equal values, the function returns before the formula, so those cases do not fail.

Expected: the same result as pandas. I plan to fix it by using the accumulated count n, which equals combined_n after every merge.

Issue Priority

Priority: 2 (default / most bugs should be filed as P2)

Issue Components

  • Component: Python SDK
  • Component: Java SDK
  • Component: Go SDK
  • Component: Typescript SDK
  • Component: IO connector
  • Component: Beam YAML
  • Component: Beam examples
  • Component: Beam playground
  • Component: Beam katas
  • Component: Website
  • Component: Infrastructure
  • Component: Spark Runner
  • Component: Flink Runner
  • Component: Prism Runner
  • Component: Hazelcast Jet Runner
  • Component: Google Cloud Dataflow Runner

Activity

  1. sohailshk commented on Nov 13, 2026

    @sohailshk
    ContributorAuthor

    .take-issue

  2. added a commit that references this issue on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions