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

Function maybe_coerce_values

pandas/core/internals/blocks.py:2189–2215  ·  view source on GitHub ↗

Input validation for values passed to __init__. Ensure that any datetime64/timedelta64 dtypes are in nanoseconds. Ensure that we do not have string dtypes. Parameters ---------- values : np.ndarray or ExtensionArray Returns ------- values : np.ndarray or Exten

(values: ArrayLike)

Source from the content-addressed store, hash-verified

2187
2188
2189def maybe_coerce_values(values: ArrayLike) -> ArrayLike:
2190 """
2191 Input validation for values passed to __init__. Ensure that
2192 any datetime64/timedelta64 dtypes are in nanoseconds. Ensure
2193 that we do not have string dtypes.
2194
2195 Parameters
2196 ----------
2197 values : np.ndarray or ExtensionArray
2198
2199 Returns
2200 -------
2201 values : np.ndarray or ExtensionArray
2202 """
2203 # Caller is responsible for ensuring NumpyExtensionArray is already extracted.
2204
2205 if isinstance(values, np.ndarray):
2206 values = ensure_wrapped_if_datetimelike(values)
2207
2208 if issubclass(values.dtype.type, str):
2209 values = np.array(values, dtype=object)
2210
2211 if isinstance(values, (DatetimeArray, TimedeltaArray)) and values.freq is not None:
2212 # freq is only stored in DatetimeIndex/TimedeltaIndex, not in Series/DataFrame
2213 values = values._with_freq(None)
2214
2215 return values
2216
2217
2218def get_block_type(dtype: DtypeObj) -> type[Block]:

Callers 9

_make_blockFunction · 0.90
make_blockFunction · 0.90
from_arrayMethod · 0.90
unpickle_blockMethod · 0.90
create_blockFunction · 0.90
applyMethod · 0.85
convertMethod · 0.85
astypeMethod · 0.85
new_block_2dFunction · 0.85

Calls 3

arrayMethod · 0.45
_with_freqMethod · 0.45

Tested by 1

create_blockFunction · 0.72