Skip to content

Commit df14530

Browse files
committed
Update display to order the rankings by rcount
1 parent 24bd4f8 commit df14530

File tree

8 files changed

+174
-9
lines changed

8 files changed

+174
-9
lines changed

.DS_Store

0 Bytes
Binary file not shown.

docs/.DS_Store

0 Bytes
Binary file not shown.

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
author = 'Wes Holliday and Eric Pacuit'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '1.16.21'
25+
release = '1.16.24'
2626
html_extra_path = ['../../axiom_tables']
2727

2828

example.ipynb

Lines changed: 146 additions & 1 deletion
Large diffs are not rendered by default.

pref_voting/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.16.21'
1+
__version__ = '1.16.24'

pref_voting/profiles.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,12 @@ def description(self):
707707
rs, cs = self.rankings_counts
708708
return f"Profile({[list([int(c) for c in r]) for r in rs]}, rcounts={[int(c) for c in cs]}, cmap={self.cmap})"
709709

710-
def display(self, cmap=None, style="pretty", curr_cands=None):
710+
def display(
711+
self,
712+
cmap=None,
713+
style="pretty",
714+
curr_cands=None,
715+
order_by_counts=False):
711716
"""Display a profile (restricted to ``curr_cands``) as an ascii table (using tabulate).
712717
713718
:param cmap: the candidate map to use (overrides the cmap associated with this profile)
@@ -732,7 +737,13 @@ def display(self, cmap=None, style="pretty", curr_cands=None):
732737

733738
rankings = self._rankings if curr_cands is None else _find_updated_profile(self._rankings, np.array([c for c in self.candidates if c not in curr_cands]), len(self.candidates))
734739

735-
print(tabulate([[cmap[c] for c in cs] for cs in rankings.transpose()], self._rcounts, tablefmt=style))
740+
if order_by_counts:
741+
rankings, rcounts = zip(*sorted(zip(rankings, self._rcounts), key=lambda x: x[1], reverse=True))
742+
rankings = np.array(rankings)
743+
else:
744+
rcounts = self._rcounts
745+
746+
print(tabulate([[cmap[c] for c in cs] for cs in rankings.transpose()], rcounts, tablefmt=style))
736747

737748
def to_preflib_instance(self):
738749
"""

pref_voting/profiles_with_ties.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,13 @@ def description(self):
808808
"""
809809
return f"ProfileWithTies({[r.rmap for r in self._rankings]}, rcounts={[int(c) for c in self.rcounts]}, cmap={self.cmap})"
810810

811-
def display(self, cmap=None, style="pretty", curr_cands=None):
811+
def display(
812+
self,
813+
cmap=None,
814+
style="pretty",
815+
curr_cands=None,
816+
order_by_counts=False,
817+
):
812818
"""Display a profile (restricted to ``curr_cands``) as an ascii table (using tabulate).
813819
814820
:param cmap: the candidate map (overrides the cmap associated with this profile)
@@ -834,7 +840,10 @@ def display(self, cmap=None, style="pretty", curr_cands=None):
834840
_rankings = [r.normalize_ranks() or r for r in _rankings]
835841
curr_cands = curr_cands if curr_cands is not None else self.candidates
836842
cmap = cmap if cmap is not None else self.cmap
837-
843+
if order_by_counts:
844+
_rankings, rcounts = zip(*sorted(zip(_rankings, self.rcounts), key=lambda x: x[1], reverse=True))
845+
else:
846+
rcounts = self.rcounts
838847
print(
839848
tabulate(
840849
[
@@ -850,7 +859,7 @@ def display(self, cmap=None, style="pretty", curr_cands=None):
850859
]
851860
for rank in self.ranks
852861
],
853-
self.rcounts,
862+
rcounts,
854863
tablefmt=style,
855864
)
856865
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[tool.poetry]
99
name = "pref_voting"
10-
version = "1.16.21"
10+
version = "1.16.24"
1111
description = "pref_voting is a Python package that contains tools to reason about elections and margin graphs, and implementations of voting methods."
1212
authors = ["Eric Pacuit <[email protected]>"]
1313
license = "MIT"

0 commit comments

Comments
 (0)