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

Method _sanitize_column

pandas/core/frame.py:5732–5757  ·  view source on GitHub ↗

Ensures new columns (which go into the BlockManager as new blocks) are always copied (or a reference is being tracked to them under CoW) and converted into an array. Parameters ---------- value : scalar, Series, or array-like Returns

(self, value)

Source from the content-addressed store, hash-verified

5730 return data
5731
5732 def _sanitize_column(self, value) -> tuple[ArrayLike, BlockValuesRefs | None]:
5733 """
5734 Ensures new columns (which go into the BlockManager as new blocks) are
5735 always copied (or a reference is being tracked to them under CoW)
5736 and converted into an array.
5737
5738 Parameters
5739 ----------
5740 value : scalar, Series, or array-like
5741
5742 Returns
5743 -------
5744 tuple of numpy.ndarray or ExtensionArray and optional BlockValuesRefs
5745 """
5746 self._ensure_valid_index(value)
5747
5748 # Using a DataFrame would mean coercing values to one dtype
5749 assert not isinstance(value, DataFrame)
5750 if is_dict_like(value):
5751 if not isinstance(value, Series):
5752 value = Series(value)
5753 return _reindex_for_setitem(value, self.index)
5754
5755 if is_list_like(value):
5756 com.require_length_match(value, self.index)
5757 return sanitize_array(value, self.index, copy=True, allow_2d=True), None
5758
5759 @property
5760 def _series(self):

Callers 3

isetitemMethod · 0.95
_set_itemMethod · 0.95
insertMethod · 0.95

Calls 5

_ensure_valid_indexMethod · 0.95
SeriesClass · 0.90
sanitize_arrayFunction · 0.90
is_dict_likeFunction · 0.85
_reindex_for_setitemFunction · 0.85

Tested by

no test coverage detected