{"record":{"id":"8056019a4ee6a3f0","repo":"pola-rs/polars","slug":"invalid-time-unit-time-unit-r","errorCode":null,"errorMessage":"invalid time unit: {time_unit!r}","messagePattern":"invalid time unit: (.+?)","errorType":"validation","errorClass":"InvalidArgument","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/testing/parametric/strategies/data.py","lineNumber":181,"sourceCode":"    \"\"\"\n    Create a strategy for generating `datetime` objects in the time unit's range.\n\n    Parameters\n    ----------\n    time_unit\n        Time unit for which the datetime objects are valid.\n    time_zone\n        Time zone for which the datetime objects are valid.\n    \"\"\"\n    if time_unit in (\"us\", \"ms\"):\n        min_value = datetime.min\n        max_value = datetime.max\n    elif time_unit == \"ns\":\n        min_value = EPOCH + timedelta(microseconds=I64_MIN // 1000 + 1)\n        max_value = EPOCH + timedelta(microseconds=I64_MAX // 1000)\n    else:\n        msg = f\"invalid time unit: {time_unit!r}\"\n        raise InvalidArgument(msg)\n\n    if time_zone is None:\n        return st.datetimes(min_value, max_value)\n\n    time_zone_info = ZoneInfo(time_zone)\n\n    # Make sure time zone offsets do not cause out-of-bound datetimes\n    if time_unit == \"ns\":\n        min_value += timedelta(days=1)\n        max_value -= timedelta(days=1)\n\n    # Return naive datetimes, but make sure they are valid for the given time zone\n    return st.datetimes(\n        min_value=min_value,\n        max_value=max_value,\n        timezones=st.just(time_zone_info),\n        allow_imaginary=False,\n    ).map(lambda dt: dt.astimezone(timezone.utc).replace(tzinfo=None))","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/pola-rs/polars/blob/68506541d2de983056c9eb244e1ea05fab377dfc/py-polars/src/polars/testing/parametric/strategies/data.py#L163-L199","documentation":"Branch failure in the datetime strategy of the parametric test framework: the requested time_unit for generating datetime objects is neither 'us', 'ms', nor 'ns', so the representable min/max range for the strategy cannot be selected.","triggerScenarios":"Thrown at py-polars/src/polars/testing/parametric/strategies/data.py:179 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a valid time unit: one of 'ms', 'us', or 'ns'."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"68506541d2de983056c9eb244e1ea05fab377dfc","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}