ValueConversionError(source_type_name, target_type_name, rejected_value=None, date_format_name=None)
Source¶
Bases: NumdaplotError
Raised when values cannot be stored in a type without losing information, or texts cannot be read as dates.
For example, decimals stored as integers, a text stored as a number, a text that does not follow the date format, or date parts that form no date. When the first rejected value is known, the message shows it.
Changed in version 0.2.0
The advice to give a format speaks of the values, for an Array as for a column.
Version history (1)
Added in version 0.1.0
Parameters:
-
source_type_name(str)Name of the
ndp.Typemember of the given values. -
target_type_name(str)Name of the
ndp.Typemember they should be stored as, orJSONfor a value JSON cannot write. -
rejected_value(object, default:None)The first value that cannot be stored. When omitted, the message names no value. A
RejectedDatePartor aRejectedDate, with the year, the month and the day, names the date parts that form no date. -
date_format_name(str | None, default:None)The name or the pattern of the date format a rejected text was read with. When omitted, or without
rejected_value, the message names no format.
Attributes:
-
source_type_nameName of the
ndp.Typemember of the given values. -
target_type_nameName of the
ndp.Typemember they should be stored as. -
rejected_valueThe first value that cannot be stored, or
Nonewhen it is not known. -
date_format_nameThe name or the pattern of the date format a rejected text was read with,
Nonefor other values. -
column_name(str | None)Name of the Table column holding the values, or
Nonefor values given to an Array.
Examples:
import numdaplot as ndp
try:
ndp.Array.from_list([1.5, 2.5], dtype=ndp.Type.INT64)
except ndp.ValueConversionError as error:
print(error)
# Cannot store FLOAT64 values as INT64 without losing information.
days = ndp.Table.from_arrays({"day": ndp.Array.from_list(["31/12/2026"])})
try:
days.convert(ndp.TableConversion(columns=["day"], dtype=ndp.Type.DATE))
except ndp.ValueConversionError as error:
print(error)
# Cannot read the TEXT value '31/12/2026' of the column 'day' as DATE with the format YEAR_MONTH_DAY.
# Give the format of the values with format=, using DateFormat or CustomDateFormat.
Methods:¶
write_message(column_text)
Source¶
Return the message, with the rejected value and the date format when they are known.
Added in version 0.1.0
Parameters:
-
column_text(str)The words naming the column after the values, or an empty text.
Returns:
-
strThe message.
Examples: