{"record":{"id":"6018389d306c8e4e","repo":"nautechsystems/nautilus_trader","slug":"pandas-is-required-for-nanosecond-precision-dateti","errorCode":null,"errorMessage":"pandas is required for nanosecond-precision datetimes","messagePattern":"pandas is required for nanosecond-precision datetimes","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/nautilus_trader/core/datetime.py","lineNumber":74,"sourceCode":"\n_NANOS_PER_MICROSECOND = 1_000\n_NANOS_PER_SECOND = 1_000_000_000\n_SECONDS_PER_DAY = 86_400\n_MICROSECOND_PRECISION_DIGITS = 6\n_UNIX_EPOCH = datetime(1970, 1, 1, tzinfo=UTC)\n\n\ndef unix_nanos_to_dt(nanos: int) -> datetime | pd.Timestamp:\n    \"\"\"\n    Return the UTC datetime for the given UNIX timestamp in nanoseconds.\n    \"\"\"\n    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: 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","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/python/nautilus_trader/core/datetime.py#L56-L92","documentation":"Raised in the pandas-free fallback of unix_nanos_to_dt when the input timestamp has a sub-microsecond nanosecond remainder: the stdlib datetime this path builds only holds microsecond precision, so converting would silently lose the trailing digits. The input at fault is any nanos value not evenly divisible by 1000.","triggerScenarios":"Thrown at python/nautilus_trader/core/datetime.py:74 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Install pandas so unix_nanos_to_dt can return a nanosecond-precision pd.Timestamp","Round or truncate the timestamp to microsecond alignment before calling the converter"],"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"}