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

Convert sets to sorted lists prior to sampling #2889

Merged
merged 3 commits into from
May 10, 2022

Conversation

jtraglia
Copy link
Member

@jtraglia jtraglia commented May 9, 2022

PR Description

According the docs for random.sample:

Deprecated since version 3.9: In the future, the population must be a sequence. Instances of set are no longer supported. The set must first be converted to a list or tuple, preferably in a deterministic order so that the sample is reproducible.

I used sorted() instead of list() to make things deterministic.

Fixed Warnings

tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py: 282 warnings
  /consensus-specs/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py:307: DeprecationWarning: Sampling from a set deprecated
  since Python 3.9 and will be removed in a subsequent version.
    return rng.sample(indices, participant_count)

tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py: 282 warnings
  /consensus-specs/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py:284: DeprecationWarning: Sampling from a set deprecated
  since Python 3.9 and will be removed in a subsequent version.
    return rng.sample(indices, participant_count)

tests/core/pyspec/eth2spec/test/altair/unittests/validator/test_validator.py::test_is_assigned_to_sync_committee
tests/core/pyspec/eth2spec/test/altair/unittests/validator/test_validator.py::test_is_assigned_to_sync_committee
tests/core/pyspec/eth2spec/test/altair/unittests/validator/test_validator.py::test_is_assigned_to_sync_committee
  /consensus-specs/tests/core/pyspec/eth2spec/test/altair/unittests/validator/test_validator.py:62: DeprecationWarning: Sampling from a set deprecated
  since Python 3.9 and will be removed in a subsequent version.
    some_pubkeys = rng.sample(disqualified_pubkeys, sample_size)

tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py: 64 warnings
  /consensus-specs/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py:203: DeprecationWarning: Sampling from a set deprecated
  since Python 3.9 and will be removed in a subsequent version.
    yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, 1))

tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py: 64 warnings
  /consensus-specs/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py:211: DeprecationWarning: Sampling from a set deprecated
  since Python 3.9 and will be removed in a subsequent version.
    yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, 1))

tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py: 64 warnings
  /consensus-specs/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py:218: DeprecationWarning: Sampling from a set deprecated
  since Python 3.9 and will be removed in a subsequent version.
    yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, len(comm) // 3))

tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py: 64 warnings
  /consensus-specs/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py:226: DeprecationWarning: Sampling from a set deprecated
  since Python 3.9 and will be removed in a subsequent version.
    yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, len(comm) // 3))

tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py: 64 warnings
  /consensus-specs/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py:233: DeprecationWarning: Sampling from a set deprecated
  since Python 3.9 and will be removed in a subsequent version.
    yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, len(comm) - 1))

tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py: 64 warnings
  /consensus-specs/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py:241: DeprecationWarning: Sampling from a set deprecated
  since Python 3.9 and will be removed in a subsequent version.
    yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, len(comm) - 1))

tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py: 64 warnings
  /consensus-specs/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py:41: DeprecationWarning: Sampling from a set deprecated
  since Python 3.9 and will be removed in a subsequent version.
    return rng.sample(indices, participant_count)

This is because sampling of sets has been deprecated in Python 3.9. I used
sorted() instead of list() so that things are deterministic.
I felt that the the lambda was a little too complicated.
Copy link
Member

@ralexstokes ralexstokes left a comment

Choose a reason for hiding this comment

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

nice one, thanks!

Copy link
Contributor

@hwwhww hwwhww left a comment

Choose a reason for hiding this comment

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

Thank you! @jtraglia

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.

None yet

3 participants