Scale

class whalrus.Scale[source]

A scale used to evaluate the candidates (for RuleRangeVoting, RuleMajorityJudgment, etc).

This parent class represents a generic scale, where two levels of the scale compare according to their internal methods __lt__, __le__, etc.

For a subclass, it is sufficient to override the method lt() and the other comparison methods will be modified accordingly (assuming it describes a total order).

Examples

>>> scale = Scale()
>>> scale.lt(1, 7)
True
argsort(some_list: list, reverse: bool = False) → list[source]

“Argsort” a list of levels.

Parameters:
  • some_list (list) – A list of levels.
  • reverse (bool) – If True, then argsort in decreasing order.
Returns:

A list of indexes.

Return type:

list

Examples

>>> Scale().argsort(['a', 'c', 'b'])
[0, 2, 1]
compare(one: object, another: object) → int[source]

Compare two levels.

Parameters:
  • one (object) – A level.
  • another (object) – A level.
Returns:

0 if they are equal, a positive number if one is greater than another, a negative number otherwise.

Return type:

int

Examples

>>> Scale().compare('a', 'z')
-1
eq(one: object, another: object) → bool[source]

Test “equal”. Cf. lt().

ge(one: object, another: object) → bool[source]

Test “greater or equal”. Cf. lt().

gt(one: object, another: object) → bool[source]

Test “greater than”. Cf. lt().

high

The highest element of the scale (or None if the scale is unbounded above).

Type:object
le(one: object, another: object) → bool[source]

Test “lower or equal”. Cf. lt().

low

The lowest element of the scale (or None if the scale is unbounded below).

Type:object
lt(one: object, another: object) → bool[source]

Test “lower than”.

Generally, only this method is overridden in the subclasses.

Parameters:
  • one (object) – A level of the scale.
  • another (object) – A level of the scale.
Returns:

True iff one is lower than another.

Return type:

bool

Examples

>>> Scale().lt('a', 'z')
True
max(iterable: Iterable[T_co]) → object[source]

Maximum of some levels.

Parameters:iterable (Iterable) – An iterable of levels (list, set, etc).

Examples

>>> Scale().max({4, 1, 12})
12
min(iterable: Iterable[T_co]) → object[source]

Minimum of some levels.

Parameters:iterable (Iterable) – An iterable of levels (list, set, etc).

Examples

>>> Scale().min({'x', 'a', 'z'})
'a'
ne(one: object, another: object) → bool[source]

Test “not equal”. Cf. lt().

sort(some_list: list, reverse: bool = False) → None[source]

Sort a list of levels (in place).

Parameters:
  • some_list (list) – A list of levels.
  • reverse (bool) – If True, then sort in decreasing order.

Examples

>>> some_list = [42, 3, 12]
>>> Scale().sort(some_list)
>>> some_list
[3, 12, 42]