@@ -425,7 +425,7 @@ def tz_localize(
425425 times.
426426
427427 nonexistent : 'shift_forward', 'shift_backward, 'NaT', timedelta, \
428- default 'raise'
428+ default 'raise'
429429 A nonexistent time does not exist in a particular timezone
430430 where clocks moved forward due to DST.
431431
@@ -455,82 +455,82 @@ def tz_localize(
455455
456456 Examples
457457 --------
458- >>> tz_naive = pd.date_range('2018-03-01 09:00', periods=3)
459- >>> tz_naive
460- DatetimeIndex(['2018-03-01 09:00:00', '2018-03-02 09:00:00',
461- '2018-03-03 09:00:00'],
462- dtype='datetime64[ns]', freq='D')
463-
464- Localize DatetimeIndex in US/Eastern time zone:
465-
466- >>> tz_aware = tz_naive.tz_localize(tz='US/Eastern')
467- >>> tz_aware
468- DatetimeIndex(['2018-03-01 09:00:00-05:00',
469- '2018-03-02 09:00:00-05:00',
470- '2018-03-03 09:00:00-05:00'],
471- dtype='datetime64[ns, US/Eastern]', freq=None)
472-
473- With the ``tz=None``, we can remove the time zone information
474- while keeping the local time (not converted to UTC):
475-
476- >>> tz_aware.tz_localize(None)
477- DatetimeIndex(['2018-03-01 09:00:00', '2018-03-02 09:00:00',
478- '2018-03-03 09:00:00'],
479- dtype='datetime64[ns]', freq=None)
480-
481- Be careful with DST changes. When there is sequential data, pandas can
482- infer the DST time:
483-
484- >>> s = pd.to_datetime(pd.Series(['2018-10-28 01:30:00',
485- ... '2018-10-28 02:00:00',
486- ... '2018-10-28 02:30:00',
487- ... '2018-10-28 02:00:00',
488- ... '2018-10-28 02:30:00',
489- ... '2018-10-28 03:00:00',
490- ... '2018-10-28 03:30:00']))
491- >>> s.dt.tz_localize('CET', ambiguous='infer')
492- 0 2018-10-28 01:30:00+02:00
493- 1 2018-10-28 02:00:00+02:00
494- 2 2018-10-28 02:30:00+02:00
495- 3 2018-10-28 02:00:00+01:00
496- 4 2018-10-28 02:30:00+01:00
497- 5 2018-10-28 03:00:00+01:00
498- 6 2018-10-28 03:30:00+01:00
499- dtype: datetime64[s, CET]
500-
501- In some cases, inferring the DST is impossible. In such cases, you can
502- pass an ndarray to the ambiguous parameter to set the DST explicitly
503-
504- >>> s = pd.to_datetime(pd.Series(['2018-10-28 01:20:00',
505- ... '2018-10-28 02:36:00',
506- ... '2018-10-28 03:46:00']))
507- >>> s.dt.tz_localize('CET', ambiguous=np.array([True, True, False]))
508- 0 2018-10-28 01:20:00+02:00
509- 1 2018-10-28 02:36:00+02:00
510- 2 2018-10-28 03:46:00+01:00
511- dtype: datetime64[s, CET]
512-
513- If the DST transition causes nonexistent times, you can shift these
514- dates forward or backwards with a timedelta object or `'shift_forward'`
515- or `'shift_backwards'`.
516-
517- >>> s = pd.to_datetime(pd.Series(['2015-03-29 02:30:00',
518- ... '2015-03-29 03:30:00'], dtype="M8[ns]"))
519- >>> s.dt.tz_localize('Europe/Warsaw', nonexistent='shift_forward')
520- 0 2015-03-29 03:00:00+02:00
521- 1 2015-03-29 03:30:00+02:00
522- dtype: datetime64[ns, Europe/Warsaw]
523-
524- >>> s.dt.tz_localize('Europe/Warsaw', nonexistent='shift_backward')
525- 0 2015-03-29 01:59:59.999999999+01:00
526- 1 2015-03-29 03:30:00+02:00
527- dtype: datetime64[ns, Europe/Warsaw]
528-
529- >>> s.dt.tz_localize('Europe/Warsaw', nonexistent=pd.Timedelta('1h'))
530- 0 2015-03-29 03:30:00+02:00
531- 1 2015-03-29 03:30:00+02:00
532- dtype: datetime64[ns, Europe/Warsaw]
533- """ # noqa: E501
458+ >>> tz_naive = pd.date_range('2018-03-01 09:00', periods=3)
459+ >>> tz_naive
460+ DatetimeIndex(['2018-03-01 09:00:00', '2018-03-02 09:00:00',
461+ '2018-03-03 09:00:00'],
462+ dtype='datetime64[ns]', freq='D')
463+
464+ Localize DatetimeIndex in US/Eastern time zone:
465+
466+ >>> tz_aware = tz_naive.tz_localize(tz='US/Eastern')
467+ >>> tz_aware
468+ DatetimeIndex(['2018-03-01 09:00:00-05:00',
469+ '2018-03-02 09:00:00-05:00',
470+ '2018-03-03 09:00:00-05:00'],
471+ dtype='datetime64[ns, US/Eastern]', freq=None)
472+
473+ With the ``tz=None``, we can remove the time zone information
474+ while keeping the local time (not converted to UTC):
475+
476+ >>> tz_aware.tz_localize(None)
477+ DatetimeIndex(['2018-03-01 09:00:00', '2018-03-02 09:00:00',
478+ '2018-03-03 09:00:00'],
479+ dtype='datetime64[ns]', freq=None)
480+
481+ Be careful with DST changes. When there is sequential data, pandas can
482+ infer the DST time:
483+
484+ >>> s = pd.to_datetime(pd.Series(['2018-10-28 01:30:00',
485+ ... '2018-10-28 02:00:00',
486+ ... '2018-10-28 02:30:00',
487+ ... '2018-10-28 02:00:00',
488+ ... '2018-10-28 02:30:00',
489+ ... '2018-10-28 03:00:00',
490+ ... '2018-10-28 03:30:00']))
491+ >>> s.dt.tz_localize('CET', ambiguous='infer')
492+ 0 2018-10-28 01:30:00+02:00
493+ 1 2018-10-28 02:00:00+02:00
494+ 2 2018-10-28 02:30:00+02:00
495+ 3 2018-10-28 02:00:00+01:00
496+ 4 2018-10-28 02:30:00+01:00
497+ 5 2018-10-28 03:00:00+01:00
498+ 6 2018-10-28 03:30:00+01:00
499+ dtype: datetime64[s, CET]
500+
501+ In some cases, inferring the DST is impossible. In such cases, you can
502+ pass an ndarray to the ambiguous parameter to set the DST explicitly
503+
504+ >>> s = pd.to_datetime(pd.Series(['2018-10-28 01:20:00',
505+ ... '2018-10-28 02:36:00',
506+ ... '2018-10-28 03:46:00']))
507+ >>> s.dt.tz_localize('CET', ambiguous=np.array([True, True, False]))
508+ 0 2018-10-28 01:20:00+02:00
509+ 1 2018-10-28 02:36:00+02:00
510+ 2 2018-10-28 03:46:00+01:00
511+ dtype: datetime64[s, CET]
512+
513+ If the DST transition causes nonexistent times, you can shift these
514+ dates forward or backwards with a timedelta object or `'shift_forward'`
515+ or `'shift_backwards'`.
516+
517+ >>> s = pd.to_datetime(pd.Series(['2015-03-29 02:30:00',
518+ ... '2015-03-29 03:30:00'], dtype="M8[ns]"))
519+ >>> s.dt.tz_localize('Europe/Warsaw', nonexistent='shift_forward')
520+ 0 2015-03-29 03:00:00+02:00
521+ 1 2015-03-29 03:30:00+02:00
522+ dtype: datetime64[ns, Europe/Warsaw]
523+
524+ >>> s.dt.tz_localize('Europe/Warsaw', nonexistent='shift_backward')
525+ 0 2015-03-29 01:59:59.999999999+01:00
526+ 1 2015-03-29 03:30:00+02:00
527+ dtype: datetime64[ns, Europe/Warsaw]
528+
529+ >>> s.dt.tz_localize('Europe/Warsaw', nonexistent=pd.Timedelta('1h'))
530+ 0 2015-03-29 03:30:00+02:00
531+ 1 2015-03-29 03:30:00+02:00
532+ dtype: datetime64[ns, Europe/Warsaw]
533+ """ # noqa: E501
534534 arr = self ._data .tz_localize (tz , ambiguous , nonexistent )
535535 return type (self )._simple_new (arr , name = self .name )
536536
@@ -987,13 +987,16 @@ def _maybe_cast_slice_bound(self, label, side: str):
987987 This function should be overloaded in subclasses that allow non-trivial
988988 casting on label-slice bounds, e.g. datetime-like indices allowing
989989 strings containing formatted datetimes.
990+
990991 Parameters
991992 ----------
992993 label : object
993994 side : {'left', 'right'}
995+
994996 Returns
995997 -------
996998 label : object
999+
9971000 Notes
9981001 -----
9991002 Value of `side` parameter should be validated in caller.
0 commit comments