{"record":{"id":"fec39b6b4180fb3f","repo":"pola-rs/polars","slug":"passing-a-list-to-search-sorted-is-ambiguous-us","errorCode":null,"errorMessage":"passing a list to `search_sorted` is ambiguous; use `Series.search_sorted(pl.Series([...]), ...)` or `Series.search_sorted(pl.lit(...), ...)`","messagePattern":"passing a list to `search_sorted` is ambiguous; use `Series\\.search_sorted\\(pl\\.Series\\(\\[\\.\\.\\.\\]\\), \\.\\.\\.\\)` or `Series\\.search_sorted\\(pl\\.lit\\(\\.\\.\\.\\), \\.\\.\\.\\)`","errorType":"exception","errorClass":"InvalidOperationError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/series/series.py","lineNumber":4114,"sourceCode":"        Series: 'set' [u32]\n        [\n            0\n            3\n            5\n        ]\n        >>> # To search for a list of values in a series, of lists, use pl.lit():\n        >>> list_s = pl.Series(\"lists\", [[0, 1], [0, 2], [1, 4]])\n        >>> list_s.search_sorted(pl.lit([0, 2]), \"left\")\n        shape: (1,)\n        Series: 'lists' [u32]\n        [\n            1\n        ]\n        \"\"\"\n        df = F.select(F.lit(self).search_sorted(element, side, descending=descending))\n        if isinstance(element, list):\n            msg = \"passing a list to `search_sorted` is ambiguous; use `Series.search_sorted(pl.Series([...]), ...)` or `Series.search_sorted(pl.lit(...), ...)`\"\n            raise InvalidOperationError(msg)\n        elif isinstance(element, (Series, pl.Expr)):\n            return df.to_series()\n        elif _check_for_numpy(element) and isinstance(element, np.ndarray):\n            return df.to_series()\n        else:\n            return df.item()\n\n    def unique(self, *, maintain_order: bool = False) -> Series:\n        \"\"\"\n        Get unique elements in series.\n\n        `null` is considered to be a unique value for the purposes of this operation.\n\n        Parameters\n        ----------\n        maintain_order\n            Maintain order of data. This requires more work.\n","sourceCodeStart":4096,"sourceCodeEnd":4132,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/series/series.py#L4096-L4132","documentation":"Series.search_sorted disallows raw Python lists as the element argument because list semantics are ambiguous (a list of values vs a single element). Polars raises InvalidOperationError telling you to wrap the list explicitly in a Series or a literal expression.","triggerScenarios":"srs.search_sorted([1, 2, 3]) — passing a list as element instead of pl.Series([1,2,3]) or pl.lit(...).","commonSituations":"Directly porting code from other libraries where lists are accepted; quick interactive lookups with a list of lookup keys.","solutions":["Wrap the list: srs.search_sorted(pl.Series([1, 2, 3]))","Use an expression: srs.search_sorted(pl.lit([1, 2, 3]))","Pass a numpy array (np.array([1,2,3])), which is also accepted"],"exampleFix":"// before\nsrs.search_sorted([10, 20])\n// after\nsrs.search_sorted(pl.Series([10, 20]))","handlingStrategy":"type-guard","validationCode":"assert not isinstance(element, list), 'wrap list in pl.Series or pl.lit for search_sorted'","typeGuard":"def search_sorted_safe(srs: pl.Series, element):\n    if isinstance(element, list):\n        element = pl.Series(element)\n    return srs.search_sorted(element)","tryCatchPattern":"try:\n    out = srs.search_sorted(element)\nexcept pl.exceptions.InvalidOperationError:\n    out = srs.search_sorted(pl.Series(element))","preventionTips":["Never pass raw lists to search_sorted","Wrap lookup keys in pl.Series or use np.ndarray","Add helper wrappers in shared code to normalize arguments"],"tags":["polars","invalid-operation","search-sorted","ambiguous-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}