Skip to content

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.Type member of the given values.

  • target_type_name (str)

    Name of the ndp.Type member they should be stored as, or JSON for 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 RejectedDatePart or a RejectedDate, 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_name

    Name of the ndp.Type member of the given values.

  • target_type_name

    Name of the ndp.Type member they should be stored as.

  • rejected_value

    The first value that cannot be stored, or None when it is not known.

  • date_format_name

    The name or the pattern of the date format a rejected text was read with, None for other values.

  • column_name (str | None)

    Name of the Table column holding the values, or None for 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:

  • str

    The message.

Examples:

import numdaplot as ndp

ndp.ValueConversionError("FLOAT64", "INT64").write_message("")
# 'Cannot store FLOAT64 values as INT64 without losing information.'

choose_message_format() Source

Return the message format fitting what is known of the rejected value.

Added in version 0.1.0

Returns:

  • str

    The format for date parts, a text read with a date format, a known value, or values in general.

Examples:

import numdaplot as ndp
from numdaplot.errors.dates.rejected_dates import RejectedDate

print(ndp.ValueConversionError("INT64", "DATE", RejectedDate(2025, 2, 31)))
# Cannot build a DATE from the year 2025, the month 2 and the day 31.