pandas-dev/pandas · error · ValueError
does not have a resolution.
Error message
{dtype=} does not have a resolution. What it means
Raised by dtype_to_unit when given an ArrowDtype whose kind is not 'm' (timedelta) or 'M' (datetime). The function exists to extract a time resolution string; for arrow types that have no temporal resolution (e.g. pyarrow strings, ints, bools) the concept is undefined, so it refuses rather than returning a nonsense unit.
Solutions
- Guard the call: only invoke dtype_to_unit when dtype.kind in 'mM'.
- Filter to temporal columns before resolving units: [c for c in df.columns if df[c].dtype.kind in 'mM'].
- If you intended a datetime, construct the right dtype: pd.ArrowDtype(pa.timestamp('us')).
Example fix
// before
unit = dtype_to_unit(pd.ArrowDtype(pa.string())) # ValueError: does not have a resolution
// after
if dtype.kind in 'mM':
unit = dtype_to_unit(dtype)
else:
unit = None Defensive patterns
Strategy: type-guard
Validate before calling
def safe_dtype_to_unit(dtype):
if isinstance(dtype, pd.ArrowDtype) and dtype.kind not in "mM":
return None # or raise a descriptive error
return dtype_to_unit(dtype) Type guard
def has_resolution(dtype) -> bool:
if isinstance(dtype, pd.ArrowDtype):
return dtype.kind in "mM"
return True Try / catch
try:
unit = dtype_to_unit(dtype)
except ValueError as e:
if "does not have a resolution" in str(e):
unit = None
else:
raise Prevention
- Filter to temporal columns before resolving units.
- Check dtype.kind in 'mM' for ArrowDtype before calling dtype_to_unit.
- Keep dtype dispatch tables mapping each kind to a resolver.
When it happens
Trigger: Calling internal dtype_to_unit(dtype) with an ArrowExtensionArray dtype that is not a pyarrow timestamp/duration; indirectly through code that converts a mixed list of dtypes to units assuming all are temporal.
Common situations: Interoperability code that iterates DataFrame dtypes and assumes every Arrow-backed column has a time resolution; passing an ArrowDtype accidentally where a DatetimeTZDtype/np.dtype was expected.
Related errors
- dtype must be PeriodDtype
- Expected array of type, got instead
- Supported timedelta64 resolutions are 's', 'ms', 'us', 'ns'
- Supported units are 's', 'ms', 'us', 'ns'
- 'unit' must be one of 's', 'ms', 'us', 'ns'
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/df26de8b04595a7b.
Report an issue: GitHub.
Appendix: source
Thrown at pandas/core/arrays/datetimelike.py:2543
def dtype_to_unit(dtype: DatetimeTZDtype | np.dtype | ArrowDtype) -> str:
"""
Return the unit str corresponding to the dtype's resolution.
Parameters
----------
dtype : DatetimeTZDtype or np.dtype
If np.dtype, we assume it is a datetime64 dtype.
Returns
-------
str
"""
if isinstance(dtype, DatetimeTZDtype):
return dtype.unit
elif isinstance(dtype, ArrowDtype):
if dtype.kind not in "mM":
raise ValueError(f"{dtype=} does not have a resolution.")
return dtype.pyarrow_dtype.unit
return np.datetime_data(dtype)[0]
View on GitHub (pinned to 3b7651241d)