{"record":{"id":"98741bdf77040214","repo":"nautechsystems/nautilus_trader","slug":"value-must-be-datetime-like","errorCode":null,"errorMessage":"value must be datetime-like","messagePattern":"value must be datetime-like","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/nautilus_trader/core/datetime.py","lineNumber":99,"sourceCode":"def dt_to_unix_nanos(value: int | str | datetime | pd.Timestamp | None) -> 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)\n\n\ndef _has_more_than_microsecond_precision(value: str) -> bool:\n    _, separator, remainder = value.partition(\".\")\n    if not separator:\n        return False\n\n    digits = 0\n\n    for char in remainder:\n        if not char.isdigit():\n            break\n        digits += 1","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/python/nautilus_trader/core/datetime.py#L81-L117","documentation":"Generic type guard in dt_to_unix_nanos: the value matched none of the accepted kinds (int nanos, ISO-8601 string, datetime, pd.Timestamp). Notably it fires for duck-typed objects that merely expose a `.value` attribute, which the converter deliberately refuses to unwrap.","triggerScenarios":"Thrown at python/nautilus_trader/core/datetime.py:99 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass an int, ISO-8601 string, datetime, or pd.Timestamp directly","Unwrap custom wrapper objects yourself, e.g. dt_to_unix_nanos(obj.value), instead of relying on attribute sniffing"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}