Skip to content
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

Use pandas duplicated() to check for duplicate index values #826

Merged
merged 2 commits into from
Jan 7, 2022

Conversation

victorlin
Copy link
Member

@victorlin victorlin commented Jan 6, 2022

Description of proposed changes

This PR uses the built-in pandas.Series.duplicated() to check for duplicates, based on @huddlej's original suggestion. Also cleans up the logic for optimal performance.

Related issue(s)

Fixes #825

Testing

  • Added test

@victorlin victorlin requested a review from huddlej January 6, 2022 22:35
@codecov
Copy link

codecov bot commented Jan 6, 2022

Codecov Report

Merging #826 (73ccb0e) into master (73a07cf) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #826      +/-   ##
==========================================
+ Coverage   33.78%   33.79%   +0.01%     
==========================================
  Files          41       41              
  Lines        5902     5903       +1     
  Branches     1465     1465              
==========================================
+ Hits         1994     1995       +1     
  Misses       3825     3825              
  Partials       83       83              
Impacted Files Coverage Δ
augur/util_support/metadata_file.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 73a07cf...73ccb0e. Read the comment docs.

@victorlin
Copy link
Member Author

[side note] While working on this, I opened a performance bug in pandas pandas-dev/pandas#45236 related to this line:

duplicate_rows = self.metadata[self.key_type].duplicated()

The docs suggest using self.metadata.duplicated(self.key_type), but it is actually slower.

Copy link
Contributor

@huddlej huddlej left a comment

Choose a reason for hiding this comment

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

Thanks, @victorlin! I confirmed that this works with the ncov scripts that call read_metadata when I have numexpr installed.

@victorlin victorlin merged commit a004d3f into master Jan 7, 2022
@victorlin victorlin deleted the victorlin/fix-utils-duplicate-check branch January 7, 2022 21:25
@huddlej huddlej added this to the Patch release 13.1.1 milestone Jan 10, 2022
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.

utils: read_metadata can crash with a value error when numexpr is installed with pandas
2 participants