cudf.DatetimeIndex.tz_localize#

DatetimeIndex.tz_localize(tz: str | None, ambiguous: Literal['NaT'] = 'NaT', nonexistent: Literal['NaT'] = 'NaT')[source]#

Localize timezone-naive data to timezone-aware data.

Parameters:
tzstr

Timezone to convert timestamps to.

Returns:
DatetimeIndex containing timezone aware timestamps.

Notes

‘NaT’ is currently the only supported option for the ambiguous and nonexistent arguments. Any ambiguous or nonexistent timestamps are converted to ‘NaT’.

Examples

>>> import cudf
>>> import pandas as pd
>>> tz_naive = cudf.date_range('2018-03-01 09:00', periods=3, freq='D')
>>> tz_aware = tz_naive.tz_localize("America/New_York")
>>> tz_aware
DatetimeIndex(['2018-03-01 09:00:00-05:00', '2018-03-02 09:00:00-05:00',
               '2018-03-03 09:00:00-05:00'],
              dtype='datetime64[ns, America/New_York]', freq='D')

Ambiguous or nonexistent datetimes are converted to NaT.

>>> s = cudf.to_datetime(cudf.Series(['2018-10-28 01:20:00',
...                                   '2018-10-28 02:36:00',
...                                   '2018-10-28 03:46:00']))
>>> s.dt.tz_localize("CET")
0    2018-10-28 01:20:00.000000000
1                              NaT
2    2018-10-28 03:46:00.000000000
dtype: datetime64[ns, CET]