{"record":{"id":"e47d285dd33e809f","repo":"pandas-dev/pandas","slug":"value-must-be-1-d-array-like-or-scalar-type-valu","errorCode":null,"errorMessage":"Value must be 1-D array-like or scalar, {type(value).__name__} is not supported","messagePattern":"Value must be 1-D array-like or scalar, (.+?) is not supported","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/base.py","lineNumber":1653,"sourceCode":"        If the values are not monotonically sorted, wrong locations\n        may be returned:\n\n        >>> ser = pd.Series([2, 1, 3])\n        >>> ser\n        0    2\n        1    1\n        2    3\n        dtype: int64\n\n        >>> ser.searchsorted(1)  # doctest: +SKIP\n        0  # wrong result, correct would be 1\n        \"\"\"\n        if isinstance(value, ABCDataFrame):\n            msg = (\n                \"Value must be 1-D array-like or scalar, \"\n                f\"{type(value).__name__} is not supported\"\n            )\n            raise ValueError(msg)\n\n        values = self._values\n        if not isinstance(values, np.ndarray):\n            # Going through EA.searchsorted directly improves performance GH#38083\n            return values.searchsorted(value, side=side, sorter=sorter)\n\n        return algorithms.searchsorted(\n            values,\n            value,\n            side=side,\n            sorter=sorter,\n        )\n\n    def drop_duplicates(self, *, keep: DropKeep = \"first\") -> Self:\n        duplicated = self._duplicated(keep=keep)\n        # error: Value of type \"IndexOpsMixin\" is not indexable\n        return self[~duplicated]  # type: ignore[index]\n","sourceCodeStart":1635,"sourceCodeEnd":1671,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/base.py#L1635-L1671","documentation":"Raised by IndexOpsMixin.searchsorted (pandas/core/base.py:1653) when the `value` argument is a 2-D object such as a DataFrame. searchsorted performs a binary search on a sorted 1-D array-like, so a rectangular DataFrame has no well-defined insertion point and is explicitly rejected before any lookup is attempted. Only 1-D array-likes (list, Series, Index, 1-D ndarray) or scalars are accepted.","triggerScenarios":"Calling `idx.searchsorted(df)` or `ser.searchsorted(df)` where `df` is a pandas DataFrame. Also triggered indirectly when a function computes a searchsorted value and accidentally passes a DataFrame column-selection that returns a DataFrame (e.g. `df[['col']]` instead of `df['col']`).","commonSituations":"Selecting with double brackets `df[['col']]` (returns DataFrame) instead of single `df['col']` (returns Series) and feeding it into searchsorted. Constructing a target from `pd.concat(..., axis=1)` and forgetting to squeeze to one dimension.","solutions":["Change the passed value to a 1-D structure: use `df['col']` (Series) or `df['col'].values` (1-D ndarray) instead of `df[['col']]`.","If you genuinely have multiple keys to locate, call searchsorted once per column in a loop or list comprehension, or use `Index.get_indexer` for vectorized lookups.","If you have a single value per row, squeeze the frame first: `df['col']` or `df.squeeze('columns')`."],"exampleFix":"# before\nidx.searchsorted(df[['date']])\n\n# after\nidx.searchsorted(df['date'])","handlingStrategy":"validation","validationCode":"import pandas as pd\n\ndef safe_searchsorted(index, value):\n    if isinstance(value, pd.DataFrame):\n        raise TypeError(\"searchsorted requires 1-D array-like or scalar, got DataFrame\")\n    return index.searchsorted(value)","typeGuard":"import pandas as pd\n\ndef is_searchsortable(value) -> bool:\n    return not isinstance(value, pd.DataFrame) and (\n        pd.api.types.is_scalar(value) or getattr(value, 'ndim', 1) == 1\n    )","tryCatchPattern":"try:\n    pos = idx.searchsorted(value)\nexcept ValueError as e:\n    if 'not supported' in str(e):\n        value = value.squeeze() if hasattr(value, 'squeeze') else value\n        pos = idx.searchsorted(value)\n    else:\n        raise","preventionTips":["Prefer single-bracket column selection df['col'] over df[['col']] before searchsorted.","Add a dimension check in helper functions that feed searchsorted.","Use Index.get_indexer for vectorized multi-key lookups."],"tags":["searchsorted","dataframe","dimensionality","indexing"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}