def _sanitize_column(self, key, value, broadcast=True):
def reindexer(value):<EOL><INDENT>if value.index.equals(self.index) or not len(self.index):<EOL><INDENT>value = value._values.copy()<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>value = value.reindex(self.index)._values<EOL><DEDENT>except Exception as e:<EOL><INDENT>if not value.index.is_unique:<EOL><INDENT>raise e<EOL><DEDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>return value<EOL><DEDENT>if isinstance(value, Series):<EOL><INDENT>value = reindexer(value)<EOL><DEDENT>elif isinstance(value, DataFrame):<EOL><INDENT>if isinstance(self.columns, MultiIndex) and key in self.columns:<EOL><INDENT>loc = self.columns.get_loc(key)<EOL>if isinstance(loc, (slice, Series, np.ndarray, Index)):<EOL><INDENT>cols = maybe_droplevels(self.columns[loc], key)<EOL>if len(cols) and not cols.equals(value.columns):<EOL><INDENT>value = value.reindex(cols, axis=<NUM_LIT:1>)<EOL><DEDENT><DEDENT><DEDENT>value = reindexer(value).T<EOL><DEDENT>elif isinstance(value, ExtensionArray):<EOL><INDENT>value = value.copy()<EOL>value = sanitize_index(value, self.index, copy=False)<EOL><DEDENT>elif isinstance(value, Index) or is_sequence(value):<EOL><INDENT>value = sanitize_index(value, self.index, copy=False)<EOL>if not isinstance(value, (np.ndarray, Index)):<EOL><INDENT>if isinstance(value, list) and len(value) > <NUM_LIT:0>:<EOL><INDENT>value = maybe_convert_platform(value)<EOL><DEDENT>else:<EOL><INDENT>value = com.asarray_tuplesafe(value)<EOL><DEDENT><DEDENT>elif value.ndim == <NUM_LIT:2>:<EOL><INDENT>value = value.copy().T<EOL><DEDENT>elif isinstance(value, Index):<EOL><INDENT>value = value.copy(deep=True)<EOL><DEDENT>else:<EOL><INDENT>value = value.copy()<EOL><DEDENT>if is_object_dtype(value.dtype):<EOL><INDENT>value = maybe_infer_to_datetimelike(value)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>infer_dtype, _ = infer_dtype_from_scalar(<EOL>value, pandas_dtype=True)<EOL>value = cast_scalar_to_array(len(self.index), value)<EOL>value = maybe_cast_to_datetime(value, infer_dtype)<EOL><DEDENT>if is_extension_type(value) or is_extension_array_dtype(value):<EOL><INDENT>return value<EOL><DEDENT>if broadcast and key in self.columns and value.ndim == <NUM_LIT:1>:<EOL><INDENT>if (not self.columns.is_unique or<EOL>isinstance(self.columns, MultiIndex)):<EOL><INDENT>existing_piece = self[key]<EOL>if isinstance(existing_piece, DataFrame):<EOL><INDENT>value = np.tile(value, (len(existing_piece.columns), <NUM_LIT:1>))<EOL><DEDENT><DEDENT><DEDENT>return np.atleast_2d(np.asarray(value))<EOL>
Ensures new columns (which go into the BlockManager as new blocks) are
always copied and converted into an array.

Parameters
----------
key : object
value : scalar, Series, or array-like
broadcast : bool, default True
    If ``key`` matches multiple duplicate column names in the
    DataFrame, this parameter indicates whether ``value`` should be
    tiled so that the returned array contains a (duplicated) column for
    each occurrence of the key. If False, ``value`` will not be tiled.

Returns
-------
numpy.ndarray