Skip to content

InvalidWeightError(weight, column_name) Source

Bases: NumdaplotError

Raised when a column of weights holds a negative weight.

A weight tells how many units a row stands for, such as the people of a population a survey answer represents.

Added in version 0.2.0

Parameters:

  • weight (float)

    The first negative weight.

  • column_name (str)

    The name of the column of weights.

Attributes:

  • weight

    The first negative weight.

  • column_name

    The name of the column of weights.

Examples:

import numdaplot as ndp

sexes = ndp.Array.from_list([1, 2])
weights = ndp.Array.from_list([300.0, -2.0])
answers = ndp.Table.from_arrays({"sex": sexes, "weight": weights})
try:
    answers.count_values(ndp.ValueCount(column="sex", weights="weight"))
except ndp.InvalidWeightError as error:
    print(error)
# Expected weights of at least 0 in the column 'weight', got -2.0.