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

Function _reconstruct_data

pandas/core/algorithms.py:192–225  ·  view source on GitHub ↗

reverse of _ensure_data Parameters ---------- values : np.ndarray or ExtensionArray dtype : np.dtype or ExtensionDtype original : AnyArrayLike Returns ------- ExtensionArray or np.ndarray

(
    values: ArrayLikeT, dtype: DtypeObj, original: AnyArrayLike
)

Source from the content-addressed store, hash-verified

190
191
192def _reconstruct_data(
193 values: ArrayLikeT, dtype: DtypeObj, original: AnyArrayLike
194) -> ArrayLikeT:
195 """
196 reverse of _ensure_data
197
198 Parameters
199 ----------
200 values : np.ndarray or ExtensionArray
201 dtype : np.dtype or ExtensionDtype
202 original : AnyArrayLike
203
204 Returns
205 -------
206 ExtensionArray or np.ndarray
207 """
208 if isinstance(values, ABCExtensionArray) and values.dtype == dtype:
209 # Catch DatetimeArray/TimedeltaArray
210 return values
211
212 if not isinstance(dtype, np.dtype):
213 # i.e. ExtensionDtype; note we have ruled out above the possibility
214 # that values.dtype == dtype
215 cls = dtype.construct_array_type()
216
217 # error: Incompatible return value type
218 # (got "ExtensionArray",
219 # expected "ndarray[tuple[Any, ...], dtype[Any]]")
220 return cls._from_sequence(values, dtype=dtype) # type: ignore[return-value]
221
222 # error: Incompatible return value type
223 # (got "ndarray[tuple[Any, ...], dtype[Any]]",
224 # expected "ExtensionArray")
225 return values.astype(dtype, copy=False) # type: ignore[return-value]
226
227
228def _ensure_arraylike(values, func_name: str) -> ArrayLike:

Callers 5

unique_with_maskFunction · 0.85
factorize_arrayFunction · 0.85
factorizeFunction · 0.85
value_counts_arraylikeFunction · 0.85
modeFunction · 0.85

Calls 3

construct_array_typeMethod · 0.45
_from_sequenceMethod · 0.45
astypeMethod · 0.45

Tested by

no test coverage detected