Skip to content

InvalidConversionError(setting_name, source_type_name, target_type_name, date_format_name=None) Source

Bases: NumdaplotError

Raised when a setting of a TableConversion does not apply to the types it converts.

For example, a date format given to a conversion between numbers, a format with a time given to a DATE column, or a time zone change given to a conversion from texts.

Changed in version 0.2.0

The advice to convert to DATETIME first speaks of the values, for an Array as for a column.

Version history (1)

Added in version 0.1.0

Parameters:

  • setting_name (str)

    Name of the setting, such as "format".

  • source_type_name (str)

    Name of the ndp.Type member of the column.

  • target_type_name (str)

    Name of the ndp.Type member it is converted to.

  • date_format_name (str | None, default: None)

    The name or the pattern of a format with a time, when dates are read or written with it. When omitted, the message names the setting and the types.

Attributes:

  • setting_name

    Name of the setting.

  • source_type_name

    Name of the ndp.Type member of the column.

  • target_type_name

    Name of the ndp.Type member it is converted to.

  • date_format_name

    The name or the pattern of a format with a time used on dates, None for other conversions.

Examples:

import numdaplot as ndp

prices = ndp.Table.from_arrays({"price": ndp.Array.from_list([12.5])})
day_first = ndp.DateFormat.DAY_MONTH_YEAR
try:
    prices.convert(ndp.TableConversion(columns=["price"], dtype=ndp.Type.TEXT, format=day_first))
except ndp.InvalidConversionError as error:
    print(error)
# The setting format does not apply to a conversion from FLOAT64 to TEXT.
days = ndp.Table.from_arrays({"day": ndp.Array.from_list(["31/12/2026 14:30"])})
day_and_time = ndp.DateFormat.DAY_MONTH_YEAR_TIME
try:
    days.convert(ndp.TableConversion(columns=["day"], dtype=ndp.Type.DATE, format=day_and_time))
except ndp.InvalidConversionError as error:
    print(error)
# The format DAY_MONTH_YEAR_TIME has a time, which DATE cannot hold.
# Convert the values to DATETIME first, then to DATE.