nautechsystems/nautilus_trader · error · ValueError

value must not be None

Error message

value must not be None

What it means

Sentinel guard at the top of dt_to_unix_nanos: the signature admits None only for typing convenience, and a None value has no meaningful nanosecond representation, so it is rejected before any conversion is attempted.

Solutions

  1. Pass an int, ISO-8601 string, datetime, or pd.Timestamp
  2. Check for None at the call site and supply a concrete timestamp instead
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at python/nautilus_trader/core/datetime.py:86 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/7d8d4a2c924f27d5. Report an issue: GitHub.

Appendix: source

Thrown at python/nautilus_trader/core/datetime.py:86

    try:
        import pandas as pd
    except ImportError:
        seconds, nanos_remainder = divmod(int(nanos), _NANOS_PER_SECOND)
        microseconds, nanos_remainder = divmod(nanos_remainder, _NANOS_PER_MICROSECOND)
        if nanos_remainder:
            raise ValueError("pandas is required for nanosecond-precision datetimes") from None

        return _UNIX_EPOCH + timedelta(seconds=seconds, microseconds=microseconds)

    return pd.Timestamp(int(nanos), unit="ns", tz="UTC")


def dt_to_unix_nanos(value: int | str | datetime | pd.Timestamp | None) -> int:
    """
    Return the UNIX timestamp in nanoseconds for the given datetime-like value.
    """
    if value is None:
        raise ValueError("value must not be None")

    try:
        import pandas as pd
    except ImportError:
        if isinstance(value, int):
            return value
        if isinstance(value, str):
            if _has_more_than_microsecond_precision(value):
                raise ValueError("pandas is required for nanosecond-precision datetimes") from None
            value = datetime.fromisoformat(value)
        if isinstance(value, datetime):
            return _datetime_to_unix_nanos(value)
        raise TypeError("value must be datetime-like") from None

    if isinstance(value, pd.Timestamp):
        return int(value.value)

    return int(pd.Timestamp(value).value)

View on GitHub (pinned to 18893faf8b)