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

Method _wrap_applied_output

pandas/core/groupby/generic.py:538–608  ·  view source on GitHub ↗

Wrap the output of SeriesGroupBy.apply into the expected result. Parameters ---------- data : Series Input data for groupby operation. values : List[Any] Applied output for each group. not_indexed_same : bool, default False

(
        self,
        data: Series,
        values: list[Any],
        not_indexed_same: bool = False,
        is_transform: bool = False,
    )

Source from the content-addressed store, hash-verified

536 return output
537
538 def _wrap_applied_output(
539 self,
540 data: Series,
541 values: list[Any],
542 not_indexed_same: bool = False,
543 is_transform: bool = False,
544 ) -> DataFrame | Series:
545 """
546 Wrap the output of SeriesGroupBy.apply into the expected result.
547
548 Parameters
549 ----------
550 data : Series
551 Input data for groupby operation.
552 values : List[Any]
553 Applied output for each group.
554 not_indexed_same : bool, default False
555 Whether the applied outputs are not indexed the same as the group axes.
556
557 Returns
558 -------
559 DataFrame or Series
560 """
561 if len(values) == 0:
562 # GH #6265
563 if is_transform:
564 # GH#47787 see test_group_on_empty_multiindex
565 res_index = data.index
566 elif not self.group_keys:
567 res_index = None
568 else:
569 res_index = self._grouper.result_index
570
571 return self.obj._constructor(
572 [],
573 name=self.obj.name,
574 index=res_index,
575 dtype=data.dtype,
576 )
577 assert values is not None
578
579 if isinstance(values[0], dict):
580 # GH #823 #24880
581 index = self._grouper.result_index
582 res_df = self.obj._constructor_expanddim(values, index=index)
583 # if self.observed is False,
584 # keep all-NaN rows created while re-indexing
585 res_ser = res_df.stack()
586 res_ser.name = self.obj.name
587 return res_ser
588 elif isinstance(values[0], (Series, DataFrame)):
589 result = self._concat_objects(
590 values,
591 not_indexed_same=not_indexed_same,
592 is_transform=is_transform,
593 )
594 if isinstance(result, Series):
595 result.name = self.obj.name

Callers

nothing calls this directly

Calls 7

default_indexFunction · 0.90
stackMethod · 0.80
_concat_objectsMethod · 0.80
__finalize__Method · 0.80
_constructorMethod · 0.45

Tested by

no test coverage detected