Skip to content

UnmatchedValueError(value, setting_name='ValueMapping') Source

Bases: NumdaplotError

Raised when a value has no new value in a ValueMapping, or is in no bracket of Brackets.

Both raise it while their others is Unmatched.ERROR.

Changed in version 0.2.0

The message of a ValueMapping also offers others=Unmatched.KEEP. The message names the Table column holding the value.

Version history (1)

Added in version 0.1.0

Parameters:

  • value (object)

    The first value without new value or bracket.

  • setting_name (str, default: 'ValueMapping')

    "ValueMapping" by default, or "Brackets": the setting that found no match, which chooses the advice.

Attributes:

  • value

    The first value without new value or bracket.

  • setting_name

    The setting that found no match.

  • column_name (str | None)

    Name of the Table column holding the value, or None for the values of an Array.

Examples:

import numdaplot as ndp

sexes = ndp.Array.from_list([1, 2, 3])
try:
    sexes.apply(ndp.ValueMapping(changes=[ndp.ValueChange(1, "Homme"), ndp.ValueChange(2, "Femme")]))
except ndp.UnmatchedValueError as error:
    print(error)
# The value 3 has no ValueChange. Add one, or give others=Unmatched.MISSING to make it missing,
# or others=Unmatched.KEEP to keep it.
ages = ndp.Table.from_arrays({"age": ndp.Array.from_list([5, 105])})
brackets = ndp.Brackets(limits=[0, 18, 100])
try:
    ages.convert(ndp.TableConversion(columns=["age"], dtype=ndp.Type.CATEGORY, format=brackets))
except ndp.UnmatchedValueError as error:
    print(error)
# The value 105 of the column 'age' is in no bracket. Open the first or the last bracket,
# or give others=Unmatched.MISSING to make it missing.

Methods:

write_message(column_text) Source

Return the message, with the advice of the setting that found no match.

Added in version 0.2.0

Parameters:

  • column_text (str)

    The words naming the column after the value, or an empty text.

Returns:

  • str

    The message.

Examples:

import numdaplot as ndp

print(ndp.UnmatchedValueError(105, "Brackets").write_message(""))
# The value 105 is in no bracket. Open the first or the last bracket,
# or give others=Unmatched.MISSING to make it missing.