{"record":{"id":"527010d3ae489144","repo":"pandas-dev/pandas","slug":"value-should-be-a-self-scalar-type-name","errorCode":null,"errorMessage":"value should be a '{self._scalar_type.__name__}', 'NaT', or array of those. Got {msg_got} instead.","messagePattern":"value should be a '(.+?)', 'NaT', or array of those\\. Got (.+?) instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/datetimelike.py","lineNumber":696,"sourceCode":"                # TODO: Could use from_sequence_of_strings if implemented\n                # Note: passing dtype is necessary for PeriodArray tests\n                value = type(self)._from_sequence(value, dtype=self.dtype)\n            except ValueError:\n                pass\n\n        if isinstance(value.dtype, CategoricalDtype):\n            # e.g. we have a Categorical holding self.dtype\n            if value.categories.dtype == self.dtype:\n                # TODO: do we need equal dtype or just comparable?\n                value = value._internal_get_values()\n                value = extract_array(value, extract_numpy=True)\n\n        if allow_object and is_object_dtype(value.dtype):\n            pass\n\n        elif not type(self)._is_recognized_dtype(value.dtype):\n            msg = self._validation_error_message(value, True)\n            raise TypeError(msg)\n\n        if self.dtype.kind in \"mM\" and not allow_object:\n            # error: \"DatetimeLikeArrayMixin\" has no attribute \"as_unit\"\n            value = value.as_unit(self.unit, round_ok=False)  # type: ignore[attr-defined]\n        return value\n\n    def _validate_setitem_value(self, value):\n        if is_list_like(value):\n            value = self._validate_listlike(value)\n        else:\n            return self._validate_scalar(value, allow_listlike=True)\n\n        return self._unbox(value)\n\n    @final\n    def _unbox(self, other) -> np.int64 | np.datetime64 | np.timedelta64 | np.ndarray:\n        \"\"\"\n        Unbox either a scalar with _unbox_scalar or an instance of our own type.","sourceCodeStart":678,"sourceCodeEnd":714,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/datetimelike.py#L678-L714","documentation":"Raised by _validate_listlike when assigning a list-like whose dtype is not recognised as compatible with the array's dtype (and the allow_object escape hatch is off). This is the list-like counterpart of 236/238: a whole array/Series of the wrong dtype (e.g. float64 array set into a datetime array, or int array into a period array) is rejected. The message includes 'or array of those' to indicate list-like inputs are allowed if correctly typed.","triggerScenarios":"arr[:] = np.array([1.0, 2.0, 3.0]) on a DatetimeArray; setting a categorical-of-float into a datetime array; fillna with an int array; setitem with a Series whose dtype is incompatible.","commonSituations":"Bulk assignment from a numeric column into a datetime column; loading data where the source column dtype differs from the target; vectorised fill operations with the wrong-typed filler.","solutions":["Convert the list-like to the matching dtype first: pd.to_datetime(series), pd.to_timedelta(series), or .astype(self.dtype).","Build a same-type array with type(self)._from_sequence(values, dtype=self.dtype).","Validate value.dtype with type(self)._is_recognized_dtype(value.dtype) before assignment."],"exampleFix":"// before\narr = pd.date_range('2020', periods=3)._data\narr[:] = [1, 2, 3]  # TypeError: value should be 'Timestamp','NaT',or array of those\n\n// after\narr[:] = pd.to_datetime(['2020-01-01','2020-01-02','2020-01-03'])","handlingStrategy":"validation","validationCode":"import pandas as pd\ndef coerce_listlike_for(arr, values):\n    cls = type(arr)\n    if not cls._is_recognized_dtype(getattr(values, 'dtype', None)):\n        return cls._from_sequence(values, dtype=arr.dtype)\n    return values","typeGuard":"import pandas as pd\nfrom typing import Any\n\ndef is_recognized_listlike(arr: Any, values: Any) -> bool:\n    dt = getattr(values, 'dtype', None)\n    return dt is not None and type(arr)._is_recognized_dtype(dt)","tryCatchPattern":"try:\n    arr[:] = values\nexcept TypeError as e:\n    if 'or array of those' in str(e):\n        cls = type(arr)\n        arr[:] = cls._from_sequence(values, dtype=arr.dtype)\n    else:\n        raise","preventionTips":["Convert source arrays with pd.to_datetime/to_timedelta before bulk assignment.","Check type(arr)._is_recognized_dtype(value.dtype) for vectorised setitem."],"tags":["datetime","listlike","dtype"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}