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

Function _maybe_localize_point

pandas/core/arrays/datetimes.py:2903–2933  ·  view source on GitHub ↗

Localize a start or end Timestamp to the timezone of the corresponding start or end Timestamp Parameters ---------- ts : start or end Timestamp to potentially localize freq : Tick, DateOffset, or None tz : str, timezone object or None ambiguous: str, localization be

(
    ts: Timestamp | None, freq, tz, ambiguous, nonexistent
)

Source from the content-addressed store, hash-verified

2901
2902
2903def _maybe_localize_point(
2904 ts: Timestamp | None, freq, tz, ambiguous, nonexistent
2905) -> Timestamp | None:
2906 """
2907 Localize a start or end Timestamp to the timezone of the corresponding
2908 start or end Timestamp
2909
2910 Parameters
2911 ----------
2912 ts : start or end Timestamp to potentially localize
2913 freq : Tick, DateOffset, or None
2914 tz : str, timezone object or None
2915 ambiguous: str, localization behavior for ambiguous times
2916 nonexistent: str, localization behavior for nonexistent times
2917
2918 Returns
2919 -------
2920 ts : Timestamp
2921 """
2922 # Make sure start and end are timezone localized if:
2923 # 1) freq = a Timedelta-like frequency (Tick)
2924 # 2) freq = None i.e. generating a linspaced range
2925 if ts is not None and ts.tzinfo is None:
2926 # Note: We can't ambiguous='infer' a singular ambiguous time; however,
2927 # we have historically defaulted ambiguous=False
2928 ambiguous = ambiguous if ambiguous != "infer" else False
2929 localize_args = {"ambiguous": ambiguous, "nonexistent": nonexistent, "tz": None}
2930 if isinstance(freq, Tick) or freq is None:
2931 localize_args["tz"] = tz
2932 ts = ts.tz_localize(**localize_args)
2933 return ts
2934
2935
2936def _generate_range(

Callers 1

_generate_rangeMethod · 0.85

Calls 1

tz_localizeMethod · 0.45

Tested by

no test coverage detected