{"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":558,"sourceCode":"            listlike inputs are allowed.\n        unbox : bool, default True\n            Whether to unbox the result before returning.  Note: unbox=False\n            skips the setitem compatibility check.\n\n        Returns\n        -------\n        self._scalar_type or NaT\n        \"\"\"\n        if isinstance(value, self._scalar_type):\n            pass\n\n        elif isinstance(value, str):\n            # NB: Careful about tzawareness\n            try:\n                value = self._scalar_from_string(value)\n            except ValueError as err:\n                msg = self._validation_error_message(value, allow_listlike)\n                raise TypeError(msg) from err\n\n        elif is_valid_na_for_dtype(value, self.dtype):\n            # GH#18295\n            value = NaT\n\n        elif isna(value):\n            # if we are dt64tz and value is dt64(\"NaT\"), dont cast to NaT,\n            #  or else we'll fail to raise in _unbox_scalar\n            msg = self._validation_error_message(value, allow_listlike)\n            raise TypeError(msg)\n\n        elif isinstance(value, self._recognized_scalars):\n            # error: Argument 1 to \"Timestamp\" has incompatible type \"object\"; expected\n            # \"integer[Any] | float | str | date | datetime | datetime64\"\n            value = self._scalar_type(value)  # type: ignore[arg-type]\n\n        else:\n            msg = self._validation_error_message(value, allow_listlike)","sourceCodeStart":540,"sourceCodeEnd":576,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/datetimelike.py#L540-L576","documentation":"Same validation path as error 255 but raised from a call site that sets allow_listlike=True (e.g., __setitem__ accepting array-like values, line 558). The message additionally tells the user an array of the scalar type is acceptable. Otherwise the trigger is identical: a string that cannot be parsed as the scalar type for the array.","triggerScenarios":"Assigning a list/array containing malformed date strings to a DatetimeArray slice: dti[0:3] = ['2020','bad']. fillna on a datetime column with a list whose element fails parsing. _validate_scalar called with allow_listlike=True from setitem.","commonSituations":"Bulk-assigning string dates where one row has a bad value. Mixed-format date strings in a single batch assignment. Locale mismatches surfacing only for some rows.","solutions":["Pre-coerce the whole batch: pd.to_datetime(values, errors='coerce') then assign.","Pass Timestamp/Timedelta objects or a DatetimeIndex instead of strings.","Filter out unparseable values before assignment.","Validate each element with pd.to_datetime(value, errors='coerce') in a loop for small batches."],"exampleFix":"# before\ndti[0:2] = ['2020-01-01', 'bad']  # TypeError\n\n# after\nvals = pd.to_datetime(['2020-01-01', 'bad'], errors='coerce')\ndti[0:2] = vals","handlingStrategy":"validation","validationCode":"import pandas as pd\nparsed = pd.to_datetime(list(values), errors='coerce')\ndti[0:len(parsed)] = parsed","typeGuard":"import pandas as pd\n\ndef all_parse_as_datetime(values) -> bool:\n    parsed = pd.to_datetime(list(values), errors='coerce')\n    return not (parsed.isna() ^ pd.isna(list(values))).any()","tryCatchPattern":"try:\n    dti[0:n] = values\nexcept TypeError as e:\n    if 'value should be' in str(e):\n        dti[0:n] = pd.to_datetime(list(values), errors='coerce')\n    else:\n        raise","preventionTips":["Coerce entire batches with pd.to_datetime before assignment.","Reject or quarantine rows with unparseable date strings upstream."],"tags":["datetimelike","validation","string-parse","setitem"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}