{"record":{"id":"6565d5a9fc0707c7","repo":"pandas-dev/pandas","slug":"passing-in-datetime64-dtype-with-no-precision-is","errorCode":null,"errorMessage":"Passing in 'datetime64' dtype with no precision is not allowed. Please pass in 'datetime64[ns]' instead.","messagePattern":"Passing in 'datetime64' dtype with no precision is not allowed\\. Please pass in 'datetime64\\[ns\\]' instead\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/datetimes.py","lineNumber":2984,"sourceCode":"\n    Raises\n    ------\n    ValueError : invalid dtype\n\n    Notes\n    -----\n    Unlike _validate_tz_from_dtype, this does _not_ allow non-existent\n    tz errors to go through\n    \"\"\"\n    if dtype is not None:\n        dtype = pandas_dtype(dtype)\n        if dtype == np.dtype(\"M8\"):\n            # no precision, disallowed GH#24806\n            msg = (\n                \"Passing in 'datetime64' dtype with no precision is not allowed. \"\n                \"Please pass in 'datetime64[ns]' instead.\"\n            )\n            raise ValueError(msg)\n\n        if (\n            isinstance(dtype, np.dtype)\n            and (dtype.kind != \"M\" or not is_supported_dtype(dtype))\n        ) or not isinstance(dtype, (np.dtype, DatetimeTZDtype)):\n            raise ValueError(\n                f\"Unexpected value for 'dtype': '{dtype}'. \"\n                \"Must be 'datetime64[s]', 'datetime64[ms]', 'datetime64[us]', \"\n                \"'datetime64[ns]' or DatetimeTZDtype'.\"\n            )\n\n        if getattr(dtype, \"tz\", None):\n            # https://github.com/pandas-dev/pandas/issues/18595\n            # Ensure that we have a standard timezone for pytz objects.\n            # Without this, things like adding an array of timedeltas and\n            # a  tz-aware Timestamp (with a tz specific to its datetime) will\n            # be incorrect(ish?) for the array as a whole\n            dtype = cast(\"DatetimeTZDtype\", dtype)","sourceCodeStart":2966,"sourceCodeEnd":3002,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/datetimes.py#L2966-L3002","documentation":"Raised by _validate_dt64_dtype when the user passes the bare 'datetime64' (numpy dtype M8 with no unit). Since GH#24806 pandas requires an explicit resolution to avoid platform-dependent unit defaulting. ValueError.","triggerScenarios":"pd.DatetimeIndex(data, dtype='datetime64'); Series.astype('datetime64'); np.dtype('datetime64') used as a dtype argument anywhere pandas validates it.","commonSituations":"Copy-pasted numpy dtype strings; older pandas code written before the precision requirement; dtype inferred from np arrays.","solutions":["Pass an explicit resolution: 'datetime64[ns]' (or s/ms/us).","Prefer pandas dtypes ('datetime64[ns]') or DatetimeTZDtype strings for aware data.","Update any helper that builds dtype strings to always include a unit."],"exampleFix":"# before\ns.astype('datetime64')\n# after\ns.astype('datetime64[ns]')","handlingStrategy":"validation","validationCode":"import re\nSUPPORTED = re.compile(r'^datetime64\\[(s|ms|us|ns)\\]$')\ndef validate_dt_dtype(dtype):\n    if dtype in ('datetime64', 'M8', np.dtype('M8')):\n        raise ValueError(\"use 'datetime64[ns]' with explicit precision\")\n    return dtype","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include a unit in datetime dtype strings.","Prefer pandas dtype strings over bare numpy ones.","Lint for 'datetime64' without brackets."],"tags":["datetime","dtype","numpy","pandas"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}