require_count#

scikitplot.rank_bm25.require_count(value, *, maximum=None, name='count')[source]#

Return value as a non-negative count within its declared maximum.

Parameters:
valueobject

Candidate count.

maximumint or None, optional

Declared ceiling. None means the caller declares no ceiling, which is not the same as a ceiling of zero.

namestr, optional

Parameter name as the calling function spells it.

Returns:
int

The validated count. Zero is valid: it is a request for nothing.

Raises:
TypeError

If the value is not an integer, or is a bool.

ValueError

If the count is negative, or above maximum.

Parameters:
  • value (Any)

  • maximum (int | None)

  • name (str)

Return type:

int

Examples

>>> require_count(5, maximum=20)
5
>>> require_count(-1)
Traceback (most recent call last):
    ...
ValueError: count -1 must be zero or greater.