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

Method _unstack

pandas/core/internals/blocks.py:1035–1077  ·  view source on GitHub ↗

Return a list of unstacked blocks of self Parameters ---------- unstacker : reshape._Unstacker fill_value : int Only used in ExtensionBlock._unstack new_placement : np.ndarray[np.intp] allow_fill : bool needs_masking : np.

(
        self,
        unstacker,
        fill_value,
        new_placement: npt.NDArray[np.intp],
        needs_masking: npt.NDArray[np.bool_],
    )

Source from the content-addressed store, hash-verified

1033 return self.make_block_same_class(new_values, new_mgr_locs)
1034
1035 def _unstack(
1036 self,
1037 unstacker,
1038 fill_value,
1039 new_placement: npt.NDArray[np.intp],
1040 needs_masking: npt.NDArray[np.bool_],
1041 ):
1042 """
1043 Return a list of unstacked blocks of self
1044
1045 Parameters
1046 ----------
1047 unstacker : reshape._Unstacker
1048 fill_value : int
1049 Only used in ExtensionBlock._unstack
1050 new_placement : np.ndarray[np.intp]
1051 allow_fill : bool
1052 needs_masking : np.ndarray[bool]
1053
1054 Returns
1055 -------
1056 blocks : list of Block
1057 New blocks of unstacked values.
1058 mask : array-like of bool
1059 The mask of columns of `blocks` we should keep.
1060 """
1061 new_values, mask = unstacker.get_new_values(
1062 self.values.T, fill_value=fill_value
1063 )
1064
1065 mask = mask.any(0)
1066 # TODO: in all tests we have mask.all(); can we rely on that?
1067
1068 # Note: these next two lines ensure that
1069 # mask.sum() == sum(len(nb.mgr_locs) for nb in blocks)
1070 # which the calling function needs in order to pass verify_integrity=False
1071 # to the BlockManager constructor
1072 new_values = new_values.T[mask]
1073 new_placement = new_placement[mask]
1074
1075 bp = BlockPlacement(new_placement)
1076 blocks = [new_block_2d(new_values, placement=bp)]
1077 return blocks, mask
1078
1079 # ---------------------------------------------------------------------
1080

Callers 1

unstackMethod · 0.45

Calls 3

new_block_2dFunction · 0.85
get_new_valuesMethod · 0.80
anyMethod · 0.45

Tested by

no test coverage detected