{"record":{"id":"7d8d4a2c924f27d5","repo":"nautechsystems/nautilus_trader","slug":"value-must-not-be-none","errorCode":null,"errorMessage":"value must not be None","messagePattern":"value must not be None","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/nautilus_trader/core/datetime.py","lineNumber":78,"sourceCode":"    try:\n        import pandas as pd\n    except ImportError:\n        seconds, nanos_remainder = divmod(int(nanos), _NANOS_PER_SECOND)\n        microseconds, nanos_remainder = divmod(nanos_remainder, _NANOS_PER_MICROSECOND)\n        if nanos_remainder:\n            raise ValueError(\"pandas is required for nanosecond-precision datetimes\") from None\n\n        return _UNIX_EPOCH + timedelta(seconds=seconds, microseconds=microseconds)\n\n    return pd.Timestamp(int(nanos), unit=\"ns\", tz=\"UTC\")\n\n\ndef dt_to_unix_nanos(value: Any) -> int:\n    \"\"\"\n    Return the UNIX timestamp in nanoseconds for the given datetime-like value.\n    \"\"\"\n    if value is None:\n        raise ValueError(\"value must not be None\")\n\n    try:\n        import pandas as pd\n    except ImportError:\n        if isinstance(value, int):\n            return value\n        if isinstance(value, str):\n            if _has_more_than_microsecond_precision(value):\n                raise ValueError(\"pandas is required for nanosecond-precision datetimes\") from None\n            value = datetime.fromisoformat(value)\n        if isinstance(value, datetime):\n            return _datetime_to_unix_nanos(value)\n        raise TypeError(\"value must be datetime-like\") from None\n\n    if isinstance(value, pd.Timestamp):\n        return int(value.value)\n\n    return int(pd.Timestamp(value).value)","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/python/nautilus_trader/core/datetime.py#L60-L96","documentation":"dt_to_unix_nanos converts datetime-like values to UNIX-ns integers and explicitly rejects None up front, rather than letting None fall into isinstance checks and returning a confusing result downstream. None is a common sentinel for 'no timestamp' in trading data, so it fails fast with 'value must not be None'.","triggerScenarios":"dt_to_unix_nanos(None) — e.g. passing an optional field straight from an order/event object or a row where the timestamp column is missing (row.get('ts') -> None).","commonSituations":"Iterating records with nullable timestamps; defaulting missing config dates to None; optional expiry/activation times fed into converters without a None branch.","solutions":["Skip or default when the value is absent: if value is None: handle/continue instead of converting","Pass a concrete datetime, pd.Timestamp, ISO string, or raw int ns","Backfill or drop rows with null timestamps before conversion loops"],"exampleFix":"# before\nts = dt_to_unix_nanos(row.get('ts_event'))  # ts_event missing -> None\n# ValueError: value must not be None\n\n# after\nts_raw = row.get('ts_event')\nif ts_raw is not None:\n    ts = dt_to_unix_nanos(ts_raw)","handlingStrategy":"validation","validationCode":"if value is None:\n    raise ValueError('timestamp value missing; cannot convert')  # or skip the record\nts = dt_to_unix_nanos(value)","typeGuard":"def is_convertible_timestamp(value: object) -> bool:\n    return value is not None","tryCatchPattern":"try:\n    ts = dt_to_unix_nanos(value)\nexcept ValueError as e:\n    if 'must not be None' in str(e):\n        continue  # skip records without timestamps\n    raise","preventionTips":["Filter null timestamps at data-load time (dropna / explicit None checks)","Avoid using None as a 'no value' sentinel in fields later fed to converters"],"tags":["python","datetime","null-check","argument-validation"],"backgroundTag":"none-argument-validation","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}