ValueMapping(changes, others=Unmatched.ERROR)
Source¶
The new value of each listed value of an Array, used by Array.apply, such as codes replaced by labels.
A missing value stays missing. The new values share one type: integers and decimals give decimals. Numbers given
to an Array of numbers take its type, as with the operators, except decimals given to integers, which give
FLOAT64. Other new values give their own type, which also holds the kept values with
others=Unmatched.KEEP. Only missing new values keep the type of the Array.
Changed in version 0.2.0
Accepts others=Unmatched.KEEP, which keeps the values without ValueChange. Numbers given to an Array
of numbers take its type, as with the operators. Only missing new values keep the type of the Array.
Version history (1)
Added in version 0.1.0
Parameters:
-
changes(list[ValueChange])The
ValueChangeof each replaced value, at least one, each old value once. The mapping keeps its own copy of the list. -
others(Unmatched, default:Unmatched.ERROR)What happens to a value without
ValueChange,Unmatched.ERRORby default.
Raises:
-
InvalidTypeErrorWhen a setting is not of the type its annotation names.
-
EmptyListErrorWhen
changesis an empty list. -
IncompatibleTypesErrorWhen the old values, or the new values, mix several families of types, such as numbers and texts.
-
DuplicateValueErrorWhen an old value appears twice.
Examples:
import numdaplot as ndp
sexes = ndp.Array.from_list([2, 1, 2])
sexes.apply(ndp.ValueMapping(changes=[ndp.ValueChange(1, "Homme"), ndp.ValueChange(2, "Femme")]))
# Array(['Femme', 'Homme', 'Femme'], dtype=TEXT)