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
)
| 2901 | |
| 2902 | |
| 2903 | def _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 | |
| 2936 | def _generate_range( |
no test coverage detected