MCPcopy
hub / github.com/pandas-dev/pandas / fillna

Method fillna

pandas/core/internals/blocks.py:1314–1345  ·  view source on GitHub ↗

fillna on the block with the value. If we fail, then convert to block to hold objects instead and try again

(
        self,
        value,
        limit: int | None = None,
        inplace: bool = False,
    )

Source from the content-addressed store, hash-verified

1312 return [self.make_block(result)]
1313
1314 def fillna(
1315 self,
1316 value,
1317 limit: int | None = None,
1318 inplace: bool = False,
1319 ) -> list[Block]:
1320 """
1321 fillna on the block with the value. If we fail, then convert to
1322 block to hold objects instead and try again
1323 """
1324 # Caller is responsible for validating limit; if int it is strictly positive
1325 inplace = validate_bool_kwarg(inplace, "inplace")
1326
1327 if not self._can_hold_na:
1328 # can short-circuit the isna call
1329 noop = True
1330 else:
1331 mask = isna(self.values)
1332 mask, noop = validate_putmask(self.values, mask)
1333
1334 if noop:
1335 # we can't process the value, but nothing to do
1336 return [self.copy(deep=False)]
1337
1338 if limit is not None:
1339 mask[mask.cumsum(self.values.ndim - 1) > limit] = False
1340
1341 if inplace:
1342 nbs = self.putmask(mask.T, value)
1343 else:
1344 nbs = self.where(value, ~mask.T)
1345 return extend_blocks(nbs)
1346
1347 def pad_or_backfill(
1348 self,

Callers 1

fillnaMethod · 0.45

Calls 8

copyMethod · 0.95
putmaskMethod · 0.95
whereMethod · 0.95
validate_bool_kwargFunction · 0.90
isnaFunction · 0.90
validate_putmaskFunction · 0.90
extend_blocksFunction · 0.85
cumsumMethod · 0.45

Tested by

no test coverage detected