Skip to content

[Python] Handle NaN in DataFrame drop_duplicates, duplicated and nunique - #40571

Merged
shunping merged 2 commits into
apache:masterfrom
anishmehta24:fix/dataframe-duplicates-nan
Oct 23, 2026
Merged

shunping merged 2 commits into
apache:masterfrom
anishmehta24:fix/dataframe-duplicates-nan

Conversation

@anishmehta24

Copy link
Copy Markdown
Contributor

Fixes #40570

drop_duplicates and duplicated colocated duplicates with groupby, which drops NaN keys (and dropna=False doesn't work with multiple columns, #21014). They now add a hash of the compared columns as an index level and partition on that, so duplicates still end up together. -0.0 is normalized first since pandas treats it as a duplicate of 0.0 but it hashes differently. Series.nunique now honours dropna.

Added tests to frames_test.py (they fail on master with KeyError) and a CHANGES.md entry. frames_test.py and pandas_doctests_test.py pass.

Written with help from Claude.

@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.93%. Comparing base (a8d6afd) to head (bbfc4b2).
⚠️ Report is 60 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40571      +/-   ##
==========================================
- Coverage   80.04%   79.93%   -0.12%     
==========================================
  Files         490      493       +3     
  Lines       82916    83414     +498     
==========================================
+ Hits        66373    66678     +305     
- Misses      16543    16736     +193     
Flag Coverage Δ
python 79.93% <100.00%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @shunping for label python.
Backup reviewer: claudevdm (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Comment thread sdks/python/apache_beam/dataframe/frames.py
Comment thread CHANGES.md Outdated
* (Python) Fixed stateful DoFns with side inputs sometimes taking the timer key coder from a side input instead of the main input, which could make the worker fail to decode timer keys with `Unknown type tag` ([#40374](https://github.com/apache/beam/issues/40374)).
* (Python) `Duration` built from float seconds now rounds to the nearest microsecond instead of truncating, which could lose a microsecond ([#40263](https://github.com/apache/beam/issues/40263)).
* (Python) `ReadFromText` with `escapechar` no longer skips a delimiter that directly follows an escaped delimiter, which merged two records into one ([#40459](https://github.com/apache/beam/issues/40459)).
<<<<<<< ours

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflict in CHANGES.md needs to be resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, conflict markers slipped in when I rebased. Rebased on master and fixed in 4d80dbe.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests on master was broken last weekend. Could you merge to the master again?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased on current master (4689e16), kept both CHANGES.md entries.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I am re-triggering the failed tests.

@anishmehta24
anishmehta24 force-pushed the fix/dataframe-duplicates-nan branch from 37f569f to 4d80dbe Compare October 16, 2026 11:41
@anishmehta24
anishmehta24 force-pushed the fix/dataframe-duplicates-nan branch from 4d80dbe to 4689e16 Compare October 21, 2026 17:54

@shunping shunping left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Will merge after the tests are passed.

@github-actions github-actions Bot added the size/s S: 10-49 lines changed label Oct 23, 2026
@shunping
shunping merged commit 5c15387 into apache:master Oct 23, 2026
87 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DataFrame API drop_duplicates and duplicated fail on rows with NaN

2 participants