pref_voting

pref_voting: The Preferential Voting Tools package for Python - Published in JOSS (2025)

https://github.com/voting-tools/pref_voting

Science Score: 95.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 11 DOI reference(s) in README and JOSS metadata
  • Academic publication links
    Links to: joss.theoj.org, zenodo.org
  • Committers with academic emails
    2 of 3 committers (66.7%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

computational-social-choice preferences preferential-voting python3 research-tool social-choice-theory utility-functions voting voting-methods

Scientific Fields

Engineering Computer Science - 60% confidence
Last synced: 4 months ago · JSON representation

Repository

pref_voting is a Python package that can be used to study and run elections with different preferential voting methods (graded voting methods and cardinal voting methods are also included for comparison).

Basic Info
Statistics
  • Stars: 20
  • Watchers: 2
  • Forks: 6
  • Open Issues: 3
  • Releases: 1
Topics
computational-social-choice preferences preferential-voting python3 research-tool social-choice-theory utility-functions voting voting-methods
Created about 3 years ago · Last pushed 4 months ago
Metadata Files
Readme Changelog Contributing License

README.md

pref_voting

DOI DOI

Tests

[!NOTE] - Documentation - Installation
- Example Notebooks
- Example Elections - ► pref_voting web app

See the COMSOC community page for an overview of other software tools related to Computational Social Choice.

Installation

The package can be installed using the pip3 package manager:

bash pip3 install pref_voting Notes: * The package requires Python 3.10 or higher and has been tested on Python 3.12.

  • Since the package uses Numba, refer to the Numba documentation for the latest supported Python version.
  • If you have both Python 2 and Python 3 installed on your system, make sure to use pip3 instead of pip to install packages for Python 3. Alternatively, you can use python3 -m pip to ensure you're using the correct version of pip. If you have modified your system's defaults or soft links, adjust accordingly.

See the installation guide for more detailed instructions.

Example Usage

A profile (of linear orders over the candidates) is created by initializing a Profile class object. Simply provide a list of rankings (each ranking is a tuple of numbers) and a list giving the number of voters with each ranking:

```python from pref_voting.profiles import Profile

rankings = [ (0, 1, 2, 3), # candidate 0 is ranked first, candidate 1 is ranked second, candidate 2 is ranked 3rd, and candidate 3 is ranked last. (2, 3, 1, 0), (3, 1, 2, 0), (1, 2, 0, 3), (1, 3, 2, 0)]

rcounts = [5, 3, 2, 4, 3] # 5 voters submitted the first ranking (0, 1, 2, 3), 3 voters submitted the second ranking, and so on.

prof = Profile(rankings, rcounts=rcounts)

prof.display() # display the profile ```

The function generate_profile is used to generate a profile for a given number of candidates and voters:

```python from prefvoting.generateprofiles import generate_profile

generate a profile using the Impartial Culture probability model

prof = generate_profile(3, 4) # prof is a Profile object with 3 candidates and 4 voters

generate a profile using the Impartial Anonymous Culture probability model

prof = generate_profile(3, 4, probmod = "IAC") # prof is a Profile object with 3 candidates and 4 voters ```

The Profile class has a number of methods that can be used to analyze the profile. For example, to determine the margin of victory between two candidates, the plurality scores, the Copeland scores, the Borda scores, the Condorcet winner, the weak Condorcet winner, and the Condorcet loser, and whether the profile is uniquely weighted, use the following code:

```python

prof = Profile([ [2, 1, 0, 3], [3, 2, 0, 1], [3, 1, 0, 2]], rcounts=[2, 2, 3])

prof.display()

print(f"The margin of 1 over 3 is {prof.margin(1, 3)}") print(f"The Plurality scores are {prof.pluralityscores()}") print(f"The Copeland scores are {prof.copelandscores()}") print(f"The Borda scores are {prof.bordascores()}") print(f"The Condorcet winner is {prof.condorcetwinner()}") print(f"The weak Condorcet winner is {prof.weakcondorcetwinner()}") print(f"The Condorcet loser is {prof.condorcetloser()}") print(f"The profile is uniquely weighted: {prof.isuniquely_weighted()}")

```

To use one of the many voting methods, import the function from pref_voting.voting_methods and apply it to the profile:

```python from prefvoting.generateprofiles import generateprofile from prefvoting.voting_methods import *

prof = generateprofile(3, 4) # create a profile with 3 candidates and 4 voters splitcycle(prof) # returns the sorted list of winning candidates split_cycle.display(prof) # displays the winning candidates

```

Additional notebooks that demonstrate how to use the package can be found in the examples directory

Some interesting political elections are analyzed using pref_voting in the election-analysis repository.

Consult the documentation https://pref-voting.readthedocs.io for a complete overview of the package.

Testing

To ensure that the package is working correctly, you can run the test suite using pytest. The test files are located in the tests directory. Follow the instructions below based on your setup.

Prerequisites

  • Python 3.9 or higher: Ensure you have a compatible version of Python installed.
  • pytest: Install pytest if it's not already installed.

Running the tests

If you are using Poetry to manage your dependencies, run the tests with:

```bash poetry run pytest

```

From the command line, run:

bash pytest

For more detailed output, add the -v or --verbose flag:

bash pytest -v

How to cite

If you would like to acknowledge our work in a scientific paper, please use the following citation:

Wesley H. Holliday and Eric Pacuit (2025). pref_voting: The Preferential Voting Tools package for Python. Journal of Open Source Software, 10(105), 7020. https://doi.org/10.21105/joss.07020

BibTeX:

```bibtex @article{HollidayPacuit2025, author = {Wesley H. Holliday and Eric Pacuit}, title = {pref_voting: The Preferential Voting Tools package for Python}, journal = {Journal of Open Source Software}, year = {2025}, publisher = {The Open Journal}, volume = {10}, number = {105}, pages = {7020}, doi = {10.21105/joss.07020} }

```

Alternatively, you can cite the archived code repository at zenodo.

Contributing

If you would like to contribute to the project, please see the contributing guidelines.

Questions?

Feel free to send an email if you have questions about the project.

License

MIT

Owner

  • Name: Voting Tools
  • Login: voting-tools
  • Kind: organization
  • Email: epacuit@umd.edu

Tools to study voting methods

JOSS Publication

pref_voting: The Preferential Voting Tools package for Python
Published
January 28, 2025
Volume 10, Issue 105, Page 7020
Authors
Wesley H. Holliday ORCID
University of California, Berkeley
Eric Pacuit ORCID
University of Maryland
Editor
Britta Westner ORCID
Tags
voting methods voting paradoxes social choice theory utility functions

GitHub Events

Total
  • Create event: 1
  • Issues event: 1
  • Release event: 1
  • Watch event: 8
  • Issue comment event: 4
  • Push event: 96
  • Pull request event: 88
  • Fork event: 3
Last Year
  • Create event: 1
  • Issues event: 1
  • Release event: 1
  • Watch event: 8
  • Issue comment event: 4
  • Push event: 96
  • Pull request event: 88
  • Fork event: 3

Committers

Last synced: 5 months ago

All Time
  • Total Commits: 566
  • Total Committers: 3
  • Avg Commits per committer: 188.667
  • Development Distribution Score (DDS): 0.502
Past Year
  • Commits: 163
  • Committers: 2
  • Avg Commits per committer: 81.5
  • Development Distribution Score (DDS): 0.399
Top Committers
Name Email Commits
Eric Pacuit e****t@u****u 282
Wesley H. Holliday w****y@b****u 278
Dominik Peters m****l@d****e 6
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 10
  • Total pull requests: 220
  • Average time to close issues: about 1 month
  • Average time to close pull requests: about 24 hours
  • Total issue authors: 5
  • Total pull request authors: 4
  • Average comments per issue: 2.0
  • Average comments per pull request: 0.03
  • Merged pull requests: 200
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 86
  • Average time to close issues: N/A
  • Average time to close pull requests: about 22 hours
  • Issue authors: 1
  • Pull request authors: 2
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.03
  • Merged pull requests: 70
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • DominikPeters (5)
  • ParadaCarleton (2)
  • mensch72 (1)
  • drvinceknight (1)
  • dmnapolitano (1)
Pull Request Authors
  • wesholliday (222)
  • DominikPeters (9)
  • elyasafko (4)
  • mensch72 (2)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 1,207 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 261
  • Total maintainers: 1
pypi.org: pref-voting

pref_voting is a Python package that contains tools to reason about elections and margin graphs, and implementations of voting methods.

  • Versions: 261
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 1,207 Last month
Rankings
Dependent packages count: 6.6%
Downloads: 11.4%
Average: 19.0%
Forks count: 23.2%
Stargazers count: 23.3%
Dependent repos count: 30.6%
Maintainers (1)
Last synced: 4 months ago

Dependencies

docs/requirements.txt pypi
  • Sphinx *
  • furo *
  • matplotlib *
  • multiprocess *
  • myst-parser *
  • networkx >=2.8
  • pref_voting *
  • scipy *
  • sphinx-copybutton *
  • sphinx-exec-code *
  • sphinx-external-toc *
  • sphinx-panels *
  • sphinx-tabs *
  • sphinx-togglebutton *
  • tabulate *
poetry.lock pypi
  • cycler 0.11.0
  • fonttools 4.34.4
  • kiwisolver 1.4.4
  • llvmlite 0.39.0
  • matplotlib 3.5.2
  • networkx 2.8.5
  • numba 0.56.0
  • numpy 1.22.4
  • packaging 21.3
  • pillow 9.2.0
  • pyparsing 3.0.9
  • python-dateutil 2.8.2
  • random2 1.0.1
  • setuptools-scm 7.0.5
  • six 1.16.0
  • tabulate 0.8.10
  • tomli 2.0.1
  • typing-extensions 4.3.0
pyproject.toml pypi
  • matplotlib ^3.5.2
  • networkx ^2.8.5
  • numba ^0.56.0
  • numpy ^1.22.0
  • python ^3.6
  • random2 ^1.0.1
  • tabulate ^0.8.10
setup.py pypi