Skip to content

IncompatibleTypesError(operation, type_names) Source

Bases: NumdaplotError

Raised when an operation, a rule, a statistic or a math function does not apply to the types it receives.

For example, a number cannot be added to a text, and Contains only applies to text.

Added in version 0.1.0

Parameters:

  • operation (str)

    Name of the operation: an operator such as "+", or a rule, statistic or function name.

  • type_names (list[str])

    Names of the ndp.Type members the operation received, in order.

Attributes:

  • operation

    Name of the operation: an operator such as "+", or a rule, statistic or function name.

  • type_names

    Names of the ndp.Type members the operation received, in order.

  • column_name (str | None)

    Name of the Table column holding the first type, or None for an Array or a type alone.

Examples:

import numdaplot as ndp

array = ndp.Array.from_list([1, 2])
try:
    array + "euros"
except ndp.IncompatibleTypesError as error:
    print(error)
# Cannot apply + to INT64 and TEXT.
sales = ndp.Table.from_arrays({"city": ndp.Array.from_list(["Paris"])})
mean_city = ndp.Calculation(column="city", function=ndp.Mean())
try:
    sales.aggregate(ndp.Aggregation(calculations=[mean_city]))
except ndp.IncompatibleTypesError as error:
    print(error)
# Cannot apply Mean to the TEXT column 'city'.

Methods:

name_column(column_name) Source

Name the Table column holding the first type in the message, unless a column is already named.

Added in version 0.1.0

Parameters:

  • column_name (str)

    The name of the column.

Examples:

import numdaplot as ndp

error = ndp.IncompatibleTypesError("Greater", ["DATETIME", "INT64"])
error.name_column("day")
print(error)
# Cannot apply Greater to the DATETIME column 'day' and INT64.