{"record":{"id":"7f6dfeb845325f75","repo":"pandas-dev/pandas","slug":"limit-must-be-none-7f6dfe","errorCode":null,"errorMessage":"limit must be None","messagePattern":"limit must be None","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/sparse/array.py","lineNumber":863,"sourceCode":"        Notes\n        -----\n        When `value` is specified, the result's ``fill_value`` depends on\n        ``self.fill_value``. The goal is to maintain low-memory use.\n\n        If ``self.fill_value`` is NA, the result dtype will be\n        ``SparseDtype(self.dtype, fill_value=value)``. This will preserve\n        amount of memory used before and after filling.\n\n        When ``self.fill_value`` is not NA, the result dtype will be\n        ``self.dtype``. Again, this preserves the amount of memory used.\n        \"\"\"\n        if isinstance(value, dict):\n            raise TypeError(\n                \"ExtensionArray.fillna does not support filling with a dict. \"\n                \"Use Series.fillna instead.\"\n            )\n        if limit is not None:\n            raise ValueError(\"limit must be None\")\n        new_values = np.where(isna(self.sp_values), value, self.sp_values)\n\n        if self._null_fill_value:\n            # This is essentially just updating the dtype.\n            new_dtype = SparseDtype(self.dtype.subtype, fill_value=value)\n        else:\n            new_dtype = self.dtype\n\n        return self._simple_new(new_values, self._sparse_index, new_dtype)\n\n    def shift(self, periods: int = 1, fill_value=None) -> Self:\n        if not len(self) or periods == 0:\n            return self.copy()\n\n        if isna(fill_value):\n            fill_value = self.dtype.na_value\n\n        subtype = np.result_type(fill_value, self.dtype.subtype)","sourceCodeStart":845,"sourceCodeEnd":881,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/sparse/array.py#L845-L881","documentation":"Raised by SparseArray.fillna when `limit` is not None. SparseArray.fillna replaces every NA in sp_values with the scalar fill in one vectorized np.where; it cannot cap the number of consecutive fills, so the limit parameter is unsupported and must be left at None.","triggerScenarios":"sparse_arr.fillna(0, limit=1); forwarding a limit kwarg from Series.fillna (which has limit support) down to the EA fillna.","commonSituations":"Generic fillna wrappers that always pass limit; migrating dense forward-fill code with limit to sparse; UI/config exposing a 'max fills' option.","solutions":["Drop the limit argument: sparse_arr.fillna(0).","If you need a fill limit, use Series-level ffill/bfill: pd.Series(arr).ffill(limit=1).","Pre-limit the NAs yourself then fill the remainder with a scalar."],"exampleFix":"// before\narr.fillna(0, limit=1)\n// after\npd.Series(arr).ffill(limit=1).fillna(0).array","handlingStrategy":"validation","validationCode":"import pandas as pd\n\ndef fillna_sparse_no_limit(arr, value, limit=None):\n    if limit is not None:\n        return pd.Series(arr).ffill(limit=limit).fillna(value).array\n    return arr.fillna(value)","typeGuard":"def limit_is_none(limit) -> bool:\n    return limit is None","tryCatchPattern":"try:\n    return arr.fillna(value, limit=limit)\nexcept ValueError as e:\n    if 'limit must be None' in str(e):\n        return pd.Series(arr).ffill(limit=limit).fillna(value).array\n    raise","preventionTips":["Don't forward limit to SparseArray.fillna.","Use Series.ffill/bfill when a fill cap is required.","Strip limit from generic fillna wrappers for sparse arrays."],"tags":["pandas","sparse","sparse-array","fillna","limit"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}