{"record":{"id":"10a8abd592e57a3b","repo":"pola-rs/polars","slug":"maxsize-cannot-be-negative-found-n","errorCode":null,"errorMessage":"`maxsize` cannot be negative; found {n}","messagePattern":"`maxsize` cannot be negative; found (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/cache.py","lineNumber":153,"sourceCode":"\n    def items(self) -> ItemsView[K, V]:\n        \"\"\"Return an iterable view of the cache's items (keys and values).\"\"\"\n        return self._items.items()\n\n    def keys(self) -> KeysView[K]:\n        \"\"\"Return an iterable view of the cache's keys.\"\"\"\n        return self._items.keys()\n\n    @property\n    def maxsize(self) -> int:\n        return self._max_size\n\n    @maxsize.setter\n    def maxsize(self, n: int) -> None:\n        \"\"\"Set new maximum cache size; cache is trimmed if value is smaller.\"\"\"\n        if n < 0:\n            msg = f\"`maxsize` cannot be negative; found {n}\"\n            raise ValueError(msg)\n        while len(self) > n:\n            self.popitem()\n        self._max_size = n\n\n    def pop(self, key: K, default: D | NoDefault = NO_DEFAULT) -> V | D:\n        \"\"\"\n        Remove specified key from the cache and return the associated value.\n\n        If the key is not found, `default` is returned (if given).\n        Otherwise, a KeyError is raised.\n        \"\"\"\n        if (item := self._items.pop(key, default)) is NO_DEFAULT:\n            msg = f\"{key!r} not found in cache\"\n            raise KeyError(msg)\n        return item\n\n    def popitem(self) -> tuple[K, V]:\n        \"\"\"Remove the least recently used value; raises KeyError if cache is empty.\"\"\"","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/py-polars/src/polars/_utils/cache.py#L135-L171","documentation":"ValueError raised by the maxsize setter of the LRU cache: a negative integer {n} was assigned to cache.maxsize. The setter validates before trimming, so any negative bound on the cache capacity is rejected immediately.","triggerScenarios":"Constructing a cache with maxsize < 0.","commonSituations":"See trigger scenarios.","solutions":["Pass a non-negative maxsize (or None for unbounded)."],"exampleFix":"cache = LRUCache(maxsize=128)","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9b5d73fd00236295624374b075d16b1fe6ec6df9","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}