ScorerPlurality

class whalrus.ScorerPlurality(*args, count_abstention: bool = False, **kwargs)[source]

A Plurality scorer for BallotPlurality.

Parameters
  • args – Cf. parent class.

  • count_abstention (bool) – If False (default), then an abstention grants no score at all. If True, then an abstention gives 0 point to each candidate (cf. below).

  • kwargs – Cf. parent class.

Examples

Typical usage:

>>> ScorerPlurality(BallotPlurality('a'), candidates={'a', 'b', 'c'}).scores_
{'a': 1, 'b': 0, 'c': 0}

Using the option count_abstention:

>>> ScorerPlurality(BallotPlurality(None), candidates={'a', 'b', 'c'}).scores_
{}
>>> ScorerPlurality(BallotPlurality(None), candidates={'a', 'b', 'c'},
...                 count_abstention=True).scores_
{'a': 0, 'b': 0, 'c': 0}
property scores_as_floats_

The scores, given as floats. It is the same as scores_, but converted to floats.

Like all conversions to floats, it is advised to use this attribute for display purposes only. For computation, you should always use scores_, which usually manipulates fractions and therefore allows for exact computation.

Raises

ValueError – If the scores cannot be converted to floats.

Type

NiceDict