Skip to content

TimeZoneMismatchError(operation, expects_time_zone, zone_names=None) Source

Bases: NumdaplotError

Raised when datetimes with a time zone meet datetimes without one, or datetimes of another time zone.

For example, a rule compares a datetime column with a time zone to a datetime without one, or TimeZoneMode.SHIFT is asked for datetimes that have no time zone.

Added in version 0.1.0

Parameters:

  • operation (str)

    What was attempted, such as "Shifting to another time zone".

  • expects_time_zone (bool)

    True when the operation needs datetimes with a time zone, False when it needs datetimes without one.

  • zone_names (list[str] | None, default: None)

    The two time zones met, such as ["Europe/Paris", "UTC"]. When omitted, one side has no time zone.

Attributes:

  • operation

    What was attempted.

  • expects_time_zone

    True when the operation needs datetimes with a time zone, False when it needs datetimes without one.

  • zone_names

    The two time zones met, or None.

Examples:

from datetime import datetime
import numdaplot as ndp

times = ndp.Table.from_arrays({"time": ndp.Array.from_list([datetime(2026, 1, 2, 10, 30)])})
paris = ndp.TimeZoneChange(mode=ndp.TimeZoneMode.SHIFT, zone=ndp.TimeZone("Europe/Paris"))
try:
    times.convert(ndp.TableConversion(columns=["time"], dtype=ndp.Type.DATETIME, timezone=paris))
except ndp.TimeZoneMismatchError as error:
    print(error)
# Shifting to another time zone needs datetimes with a time zone.