Skip to content

CI: Fix flaky test_value_counts_null #32449

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

Conversation

tm.assert_series_equal(obj.value_counts(), expected)
# sort_index to avoid switched order when values share the same count
expected = expected.sort_index()
result = obj.value_counts().sort_index()
Copy link
Member

Choose a reason for hiding this comment

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

I think the result should just be obj.value_counts() for the test to be considered a valid test.

is it feasible for expected to be constructed to create the expected sort order or is the sort order tested elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I generally agree, but this is the only solution I found to work consistently on CI.

What I've found so far is the following:

  • Usually, value_counts preserves the order from obj if multiple values share the same count
  • This scenario is covered by the current test design/implementation
  • However, this seems to break on CI (I could only see it breaking for float16 on Windows py36_np15, but there might be more)
  • Locally (mac, py36) I cannot reproduce the flakiness, even when running it many times

So this might actually be a bug. I never worked with Cython, so it's hard for me to trace this deeper. It might be an issue in value_count_float64 in pandas/_libs/hashtable_func_helper.pxi

My suggestion would be to

  1. adjust the current code to only call sort_index for float16 for now
  2. merge this PR
  3. open an issue for the potential bug

By seeing if the test is still flaky afterwards we can gather more data about its relation to float16 etc.

Wdyt @simonjayhawkins?

Copy link
Member

Choose a reason for hiding this comment

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

  1. sounds good with a TODO

could it be not related to float16, just duplicate values are more likely due to decreased resolution.

Copy link
Contributor Author

@SaturnFromTitan SaturnFromTitan Mar 5, 2020

Choose a reason for hiding this comment

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

I don't think so. If it's about duplicated values alone then it should always fail for repeats, see here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

could just revert #32281 for now instead @jbrockmendel ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I come to wonder if the order of values with the same count is actually deterministic. If not, is there an alternative to using sort_index on result and expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could just revert #32281 for now instead @jbrockmendel ?

I think merging this PR is better than reverting the #32281. In the previous version we just skipped all tests with duplicated values. Here we at least test that the values are correct, even though we don't validate that they are ordered consistently.

@simonjayhawkins simonjayhawkins added the CI Continuous Integration label Mar 5, 2020
@simonjayhawkins simonjayhawkins added this to the 1.1 milestone Mar 5, 2020
Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

Thanks @SaturnFromTitan lgtm pending green

# sort_index to avoid switched order when values share the same count
result = result.sort_index()
expected = expected.sort_index()
# TODO: Order of entries with the same count is inconsistent on CI (gh-32449)
Copy link
Member

Choose a reason for hiding this comment

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

Is there an open issue for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

xref: #32514

@SaturnFromTitan
Copy link
Contributor Author

@WillAyd @simonjayhawkins I added a follow-up issue and will come back to it later. Otherwise I think I addressed all comments, so this should be good to merge

@simonjayhawkins simonjayhawkins merged commit 45d412f into pandas-dev:master Mar 7, 2020
@simonjayhawkins
Copy link
Member

Thanks @SaturnFromTitan

@TomAugspurger
Copy link
Contributor

Generally fixes for flaky tests should be backported. Does the 1.0.x branch suffer from the original flakiness?

@simonjayhawkins
Copy link
Member

no. #32281 was not backported.

@TomAugspurger
Copy link
Contributor

Great, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants