Skip to content

Commit 956c3f4

Browse files
author
cloudboat
committed
Supplement the required spaces
1 parent 649b051 commit 956c3f4

File tree

2 files changed

+86
-79
lines changed

2 files changed

+86
-79
lines changed

pandas/core/indexes/datetimelike.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,12 +1065,13 @@ def take(
10651065
"""
10661066
Return a new Index of the values selected by the indices.
10671067
For internal compatibility with numpy arrays.
1068+
10681069
Parameters
10691070
----------
10701071
indices : array-like
10711072
Indices to be taken.
1072-
axis : int, optional
1073-
The axis over which to select values, always 0.
1073+
axis : {0 or 'index'}, optional
1074+
The axis over which to select values, always 0 or 'index'.
10741075
allow_fill : bool, default True
10751076
How to handle negative values in `indices`.
10761077
* False: negative values in `indices` indicate positional indices
@@ -1084,15 +1085,18 @@ def take(
10841085
-1 are regarded as NA. If Index doesn't hold NA, raise ValueError.
10851086
**kwargs
10861087
Required for compatibility with numpy.
1088+
10871089
Returns
10881090
-------
10891091
Index
10901092
An index formed of elements at the given indices. Will be the same
10911093
type as self, except for RangeIndex.
1094+
10921095
See Also
10931096
--------
10941097
numpy.ndarray.take: Return an array formed from the
10951098
elements of a at the given indices.
1099+
10961100
Examples
10971101
--------
10981102
>>> idx = pd.Index(["a", "b", "c"])

pandas/core/indexes/datetimes.py

Lines changed: 80 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)