{"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":868,"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":850,"sourceCodeEnd":886,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/sparse/array.py#L850-L886","documentation":"SparseArray.fillna raises ValueError when limit is not None. Sparse filling operates on sp_values via np.where, which cannot respect a forward fill limit, so limit is structurally unsupported.","triggerScenarios":"Calling arr.fillna(value, limit=1) or any fillna with a non-None limit on a SparseArray.","commonSituations":"Porting dense Series.fillna(value, limit=N) code to a sparse-backed Series; generic fillna wrappers that always forward limit.","solutions":["Drop the limit argument when calling fillna on a SparseArray.","If limit semantics are required, operate on a dense Series: pd.Series(arr).fillna(value, limit=N), then re-sparse.","Implement limit-aware filling on the dense materialization and rebuild the SparseArray."],"exampleFix":"// before\narr.fillna(0.0, limit=2)  # raises\n// after\npd.Series(arr).fillna(0.0, limit=2).astype(pd.SparseDtype()).array","handlingStrategy":"validation","validationCode":"def safe_fillna(arr, value=None, limit=None):\n    if limit is not None and hasattr(arr, 'sp_index'):  # SparseArray\n        return pd.Series(arr).fillna(value, limit=limit).array\n    return arr.fillna(value=value, limit=limit)","typeGuard":"def sparse_rejects_limit(arr, limit) -> bool:\n    from pandas.core.arrays.sparse import SparseArray\n    return isinstance(arr, SparseArray) and limit is not None","tryCatchPattern":"try:\n    arr.fillna(value, limit=limit)\nexcept ValueError as e:\n    if \"limit must be None\" in str(e):\n        arr = pd.Series(arr).fillna(value, limit=limit).array\n    else:\n        raise","preventionTips":["Drop limit when calling fillna on SparseArray.","Move limit-aware filling to a dense Series pipeline."],"tags":["sparse","fillna","limit","series-api"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}