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

Method apply_standard

pandas/core/apply.py:1560–1587  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1558 return result
1559
1560 def apply_standard(self) -> DataFrame | Series:
1561 # caller is responsible for ensuring that f is Callable
1562 func = cast(Callable, self.func)
1563 obj = self.obj
1564
1565 if isinstance(func, np.ufunc):
1566 with np.errstate(all="ignore"):
1567 return func(obj, *self.args, **self.kwargs)
1568 elif not self.by_row:
1569 return func(obj, *self.args, **self.kwargs)
1570
1571 if self.args or self.kwargs:
1572 # _map_values does not support args/kwargs
1573 def curried(x):
1574 return func(x, *self.args, **self.kwargs)
1575
1576 else:
1577 curried = func
1578 mapped = obj._map_values(mapper=curried)
1579
1580 if len(mapped) and isinstance(mapped[0], ABCSeries):
1581 # GH#43986 Need to do list(mapped) in order to get treated as nested
1582 # See also GH#25959 regarding EA support
1583 return obj._constructor_expanddim(list(mapped), index=obj.index)
1584 else:
1585 return obj._constructor(mapped, index=obj.index).__finalize__(
1586 obj, method="apply"
1587 )
1588
1589
1590class GroupByApply(Apply):

Callers 1

applyMethod · 0.95

Calls 5

_map_valuesMethod · 0.80
__finalize__Method · 0.80
funcFunction · 0.70
_constructorMethod · 0.45

Tested by

no test coverage detected