{"record":{"id":"645df86ecbfb4222","repo":"pandas-dev/pandas","slug":"value-should-be-a-timestamp","errorCode":null,"errorMessage":"'value' should be a Timestamp.","messagePattern":"'value' should be a Timestamp\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/datetimes.py","lineNumber":554,"sourceCode":"                if len(i8values)\n                else 0\n            )\n            if not left_inclusive or not right_inclusive:\n                if not left_inclusive and len(i8values) and i8values[0] == start_i8:\n                    i8values = i8values[1:]\n                if not right_inclusive and len(i8values) and i8values[-1] == end_i8:\n                    i8values = i8values[:-1]\n\n        dt64_values = i8values.view(f\"datetime64[{unit}]\")\n        dtype = tz_to_dtype(tz, unit=unit)\n        return cls._simple_new(dt64_values, dtype=dtype)\n\n    # -----------------------------------------------------------------\n    # DatetimeLike Interface\n\n    def _unbox_scalar(self, value) -> np.datetime64:\n        if not isinstance(value, self._scalar_type) and value is not NaT:\n            raise ValueError(\"'value' should be a Timestamp.\")\n        self._check_compatible_with(value)\n        if value is NaT:\n            return np.datetime64(value._value, self.unit)\n        else:\n            return value.as_unit(self.unit, round_ok=False).asm8\n\n    def _scalar_from_string(self, value) -> Timestamp | NaTType:\n        return Timestamp(value, tz=self.tz)\n\n    def _check_compatible_with(self, other) -> None:\n        if other is NaT:\n            return\n        self._assert_tzawareness_compat(other)\n\n    # -----------------------------------------------------------------\n    # Descriptive Properties\n\n    def _box_func(self, x: np.datetime64) -> Timestamp | NaTType:","sourceCodeStart":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/datetimes.py#L536-L572","documentation":"Raised by DatetimeArray._unbox_scalar when a value being placed/compared into the array is neither a Timestamp, nor NaT, nor an instance of the array's scalar_type. The array can only hold pandas Timestamps (or NaT) so any other type is rejected at the boundary instead of being coerced into a wrong unit.","triggerScenarios":"Assigning a python datetime.date, datetime.time, a numpy.datetime64 of a mismatched unit, a string that wasn't parsed, or a raw int into a DatetimeArray; calling internal .insert/setitem with a non-Timestamp. e.g. dta[0] = datetime.date(2020,1,1) on a tz-aware array in some code paths.","commonSituations":"Mixing datetime.date and datetime.datetime objects; passing epoch ints thinking they'd be interpreted; cross-library objects (numpy datetime64) of a different resolution than the array.","solutions":["Wrap the value in pd.Timestamp(...) before assignment.","Parse strings/ints via pd.to_datetime first so they become Timestamps.","For .date() inputs, convert with pd.Timestamp(date)."],"exampleFix":"# before\ndta = pd.DatetimeIndex(['2020-01-01']).array\ndta[0] = datetime.date(2020, 1, 2)\n\n# after\ndta[0] = pd.Timestamp(datetime.date(2020, 1, 2))","handlingStrategy":"type-guard","validationCode":"if not isinstance(value, (pd.Timestamp, type(pd.NaT))):\n    value = pd.Timestamp(value)","typeGuard":"def is_assignable_to_dta(v) -> bool:\n    return isinstance(v, pd.Timestamp) or v is pd.NaT","tryCatchPattern":"try:\n    dta[0] = value\nexcept (TypeError, ValueError) as e:\n    if 'should be a Timestamp' in str(e):\n        dta[0] = pd.Timestamp(value)\n    else: raise","preventionTips":["Wrap inbound values in pd.Timestamp at the boundary.","Parse via pd.to_datetime instead of assigning raw date/int/string objects."],"tags":["datetime","scalar","setitem","type-error"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}