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

Function ensure_wrapped_if_datetimelike

pandas/core/construction.py:495–512  ·  view source on GitHub ↗

Wrap datetime64 and timedelta64 ndarrays in DatetimeArray/TimedeltaArray.

(arr)

Source from the content-addressed store, hash-verified

493
494
495def ensure_wrapped_if_datetimelike(arr):
496 """
497 Wrap datetime64 and timedelta64 ndarrays in DatetimeArray/TimedeltaArray.
498 """
499 if isinstance(arr, np.ndarray):
500 if arr.dtype.kind == "M":
501 from pandas.core.arrays import DatetimeArray
502
503 dtype = get_supported_dtype(arr.dtype)
504 return DatetimeArray._from_sequence(arr, dtype=dtype)
505
506 elif arr.dtype.kind == "m":
507 from pandas.core.arrays import TimedeltaArray
508
509 dtype = get_supported_dtype(arr.dtype)
510 return TimedeltaArray._from_sequence(arr, dtype=dtype)
511
512 return arr
513
514
515def sanitize_masked_array(data: ma.MaskedArray) -> np.ndarray:

Callers 15

modeFunction · 0.90
searchsortedFunction · 0.90
union_with_duplicatesFunction · 0.90
_arith_methodMethod · 0.90
series_generatorMethod · 0.90
_valuesMethod · 0.90
arithmetic_opFunction · 0.90
comparison_opFunction · 0.90
logical_opFunction · 0.90
new_methodFunction · 0.90
maybe_coerce_valuesFunction · 0.90
fast_xsMethod · 0.90

Calls 1

_from_sequenceMethod · 0.45

Tested by

no test coverage detected