Localize tz-naive Datetime Array/Index to tz-aware Datetime Array/Index. This method takes a time zone (tz) naive Datetime Array/Index object and makes this time zone aware. It does not move the time to another time zone. This method can also be used to do
(
self,
tz,
ambiguous: TimeAmbiguous = "raise",
nonexistent: TimeNonexistent = "raise",
)
| 941 | |
| 942 | @dtl.ravel_compat |
| 943 | def tz_localize( |
| 944 | self, |
| 945 | tz, |
| 946 | ambiguous: TimeAmbiguous = "raise", |
| 947 | nonexistent: TimeNonexistent = "raise", |
| 948 | ) -> Self: |
| 949 | """ |
| 950 | Localize tz-naive Datetime Array/Index to tz-aware Datetime Array/Index. |
| 951 | |
| 952 | This method takes a time zone (tz) naive Datetime Array/Index object |
| 953 | and makes this time zone aware. It does not move the time to another |
| 954 | time zone. |
| 955 | |
| 956 | This method can also be used to do the inverse -- to create a time |
| 957 | zone unaware object from an aware object. To that end, pass `tz=None`. |
| 958 | |
| 959 | Parameters |
| 960 | ---------- |
| 961 | tz : str, zoneinfo.ZoneInfo,, pytz.timezone, dateutil.tz.tzfile, datetime.tzinfo or None |
| 962 | Time zone to convert timestamps to. Passing ``None`` will |
| 963 | remove the time zone information preserving local time. |
| 964 | ambiguous : 'infer', 'NaT', bool array, default 'raise' |
| 965 | When clocks moved backward due to DST, ambiguous times may arise. |
| 966 | For example in Central European Time (UTC+01), when going from |
| 967 | 03:00 DST to 02:00 non-DST, 02:30:00 local time occurs both at |
| 968 | 00:30:00 UTC and at 01:30:00 UTC. In such a situation, the |
| 969 | `ambiguous` parameter dictates how ambiguous times should be |
| 970 | handled. |
| 971 | |
| 972 | - 'infer' will attempt to infer fall dst-transition hours based on |
| 973 | order |
| 974 | - bool-ndarray where True signifies a DST time, False signifies a |
| 975 | non-DST time (note that this flag is only applicable for |
| 976 | ambiguous times) |
| 977 | - 'NaT' will return NaT where there are ambiguous times |
| 978 | - 'raise' will raise a ValueError if there are ambiguous |
| 979 | times. |
| 980 | |
| 981 | nonexistent : 'shift_forward', 'shift_backward, 'NaT', timedelta, \ |
| 982 | default 'raise' |
| 983 | A nonexistent time does not exist in a particular timezone |
| 984 | where clocks moved forward due to DST. |
| 985 | |
| 986 | - 'shift_forward' will shift the nonexistent time forward to the |
| 987 | closest existing time |
| 988 | - 'shift_backward' will shift the nonexistent time backward to the |
| 989 | closest existing time |
| 990 | - 'NaT' will return NaT where there are nonexistent times |
| 991 | - timedelta objects will shift nonexistent times by the timedelta |
| 992 | - 'raise' will raise a ValueError if there are |
| 993 | nonexistent times. |
| 994 | |
| 995 | Returns |
| 996 | ------- |
| 997 | Same type as self |
| 998 | Array/Index converted to the specified time zone. |
| 999 | |
| 1000 | Raises |
no test coverage detected