{"record":{"id":"df26de8b04595a7b","repo":"pandas-dev/pandas","slug":"dtype-does-not-have-a-resolution","errorCode":null,"errorMessage":"{dtype=} does not have a resolution.","messagePattern":"(.+?) does not have a resolution\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/datetimelike.py","lineNumber":2530,"sourceCode":"\ndef dtype_to_unit(dtype: DatetimeTZDtype | np.dtype | ArrowDtype) -> str:\n    \"\"\"\n    Return the unit str corresponding to the dtype's resolution.\n\n    Parameters\n    ----------\n    dtype : DatetimeTZDtype or np.dtype\n        If np.dtype, we assume it is a datetime64 dtype.\n\n    Returns\n    -------\n    str\n    \"\"\"\n    if isinstance(dtype, DatetimeTZDtype):\n        return dtype.unit\n    elif isinstance(dtype, ArrowDtype):\n        if dtype.kind not in \"mM\":\n            raise ValueError(f\"{dtype=} does not have a resolution.\")\n        return dtype.pyarrow_dtype.unit\n    return np.datetime_data(dtype)[0]\n","sourceCodeStart":2512,"sourceCodeEnd":2533,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/datetimelike.py#L2512-L2533","documentation":"Raised by dtype_to_unit when an ArrowDtype is passed whose kind is not datetime ('M') or timedelta ('m'). The function exists to extract a time resolution string; only temporal Arrow dtypes carry one, so any other Arrow type (int, string, bool) is rejected.","triggerScenarios":"Internally calling dtype_to_unit on a non-temporal pandas ArrowDtype (e.g. pd.ArrowDtype(pa.int64()), pd.ArrowDtype(pa.string())). Reachable when code generic over dtypes routes an Arrow column through the temporal conversion path.","commonSituations":"Generic type-coercion helpers that assume every Arrow dtype is temporal; mislabeling a column dtype; mixing Arrow-backed numeric columns into a datetime cast pipeline.","solutions":["Guard the call with dtype.kind in 'mM' before invoking dtype_to_unit.","Ensure the ArrowDtype is temporal: pd.ArrowDtype(pa.timestamp('ns')) or pa.duration('ns').","Branch on dtype before dispatching to temporal-specific helpers."],"exampleFix":"# before\ndtype_to_unit(pd.ArrowDtype(pa.int64()))\n\n# after\nif dtype.kind in 'mM':\n    unit = dtype_to_unit(dtype)\nelse:\n    raise TypeError(f'{dtype} is not temporal')","handlingStrategy":"type-guard","validationCode":"if isinstance(dtype, pd.ArrowDtype) and dtype.kind not in 'mM':\n    raise TypeError(f'{dtype} is not temporal; cannot resolve a unit')","typeGuard":"def is_temporal_arrow(dtype) -> bool:\n    return isinstance(dtype, pd.ArrowDtype) and dtype.kind in 'mM'","tryCatchPattern":"try:\n    dtype_to_unit(dtype)\nexcept ValueError as e:\n    if 'does not have a resolution' in str(e):\n        # not temporal; pick a default unit or skip\n        unit = 'ns'\n    else: raise","preventionTips":["Branch on dtype.kind before dispatching Arrow dtypes to temporal helpers.","Document which dtypes a generic function accepts."],"tags":["arrow","dtype","datetime","timedelta","validation"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}