Skip to content

Commit 727e3c9

Browse files
FHaasePingviinituutti
authored andcommitted
Fix PEP-8 issues in timedeltas.rst (pandas-dev#23905)
Signed-off-by: Fabian Haase <[email protected]>
1 parent d6239db commit 727e3c9

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

doc/source/timedeltas.rst

+21-21
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@
44
.. ipython:: python
55
:suppress:
66
7-
import datetime
87
import numpy as np
98
import pandas as pd
9+
1010
np.random.seed(123456)
11-
randn = np.random.randn
12-
randint = np.random.randint
1311
np.set_printoptions(precision=4, suppress=True)
14-
pd.options.display.max_rows=15
15-
import dateutil
16-
import pytz
17-
from dateutil.relativedelta import relativedelta
18-
from pandas.tseries.offsets import *
12+
pd.options.display.max_rows = 15
1913
2014
.. _timedeltas.timedeltas:
2115

@@ -37,6 +31,8 @@ You can construct a ``Timedelta`` scalar through various arguments:
3731

3832
.. ipython:: python
3933
34+
import datetime
35+
4036
# strings
4137
pd.Timedelta('1 days')
4238
pd.Timedelta('1 days 00:00:00')
@@ -74,13 +70,14 @@ You can construct a ``Timedelta`` scalar through various arguments:
7470

7571
.. ipython:: python
7672
77-
pd.Timedelta(Second(2))
73+
pd.Timedelta(pd.offsets.Second(2))
7874
7975
Further, operations among the scalars yield another scalar ``Timedelta``.
8076

8177
.. ipython:: python
8278
83-
pd.Timedelta(Day(2)) + pd.Timedelta(Second(2)) + pd.Timedelta('00:00:00.000123')
79+
pd.Timedelta(pd.offsets.Day(2)) + pd.Timedelta(pd.offsets.Second(2)) +\
80+
pd.Timedelta('00:00:00.000123')
8481
8582
to_timedelta
8683
~~~~~~~~~~~~
@@ -135,8 +132,8 @@ subtraction operations on ``datetime64[ns]`` Series, or ``Timestamps``.
135132
.. ipython:: python
136133
137134
s = pd.Series(pd.date_range('2012-1-1', periods=3, freq='D'))
138-
td = pd.Series([ pd.Timedelta(days=i) for i in range(3) ])
139-
df = pd.DataFrame(dict(A = s, B = td))
135+
td = pd.Series([pd.Timedelta(days=i) for i in range(3)])
136+
df = pd.DataFrame({'A': s, 'B': td})
140137
df
141138
df['C'] = df['A'] + df['B']
142139
df
@@ -145,8 +142,8 @@ subtraction operations on ``datetime64[ns]`` Series, or ``Timestamps``.
145142
s - s.max()
146143
s - datetime.datetime(2011, 1, 1, 3, 5)
147144
s + datetime.timedelta(minutes=5)
148-
s + Minute(5)
149-
s + Minute(5) + Milli(5)
145+
s + pd.offsets.Minute(5)
146+
s + pd.offsets.Minute(5) + pd.offsets.Milli(5)
150147
151148
Operations with scalars from a ``timedelta64[ns]`` series:
152149

@@ -184,7 +181,7 @@ Operands can also appear in a reversed order (a singular object operated with a
184181
A = s - pd.Timestamp('20120101') - pd.Timedelta('00:05:05')
185182
B = s - pd.Series(pd.date_range('2012-1-2', periods=3, freq='D'))
186183
187-
df = pd.DataFrame(dict(A=A, B=B))
184+
df = pd.DataFrame({'A': A, 'B': B})
188185
df
189186
190187
df.min()
@@ -232,7 +229,8 @@ Numeric reduction operation for ``timedelta64[ns]`` will return ``Timedelta`` ob
232229

233230
.. ipython:: python
234231
235-
y2 = pd.Series(pd.to_timedelta(['-1 days +00:00:05', 'nat', '-1 days +00:00:05', '1 days']))
232+
y2 = pd.Series(pd.to_timedelta(['-1 days +00:00:05', 'nat',
233+
'-1 days +00:00:05', '1 days']))
236234
y2
237235
y2.mean()
238236
y2.median()
@@ -250,8 +248,10 @@ Note that division by the NumPy scalar is true division, while astyping is equiv
250248

251249
.. ipython:: python
252250
253-
td = pd.Series(pd.date_range('20130101', periods=4)) - \
254-
pd.Series(pd.date_range('20121201', periods=4))
251+
december = pd.Series(pd.date_range('20121201', periods=4))
252+
january = pd.Series(pd.date_range('20130101', periods=4))
253+
td = january - december
254+
255255
td[2] += datetime.timedelta(minutes=5, seconds=3)
256256
td[3] = np.nan
257257
td
@@ -360,8 +360,8 @@ or ``np.timedelta64`` objects. Passing ``np.nan/pd.NaT/nat`` will represent miss
360360

361361
.. ipython:: python
362362
363-
pd.TimedeltaIndex(['1 days', '1 days, 00:00:05',
364-
np.timedelta64(2,'D'), datetime.timedelta(days=2,seconds=2)])
363+
pd.TimedeltaIndex(['1 days', '1 days, 00:00:05', np.timedelta64(2, 'D'),
364+
datetime.timedelta(days=2, seconds=2)])
365365
366366
The string 'infer' can be passed in order to set the frequency of the index as the
367367
inferred frequency upon creation:
@@ -458,7 +458,7 @@ Similarly to frequency conversion on a ``Series`` above, you can convert these i
458458

459459
.. ipython:: python
460460
461-
tdi / np.timedelta64(1,'s')
461+
tdi / np.timedelta64(1, 's')
462462
tdi.astype('timedelta64[s]')
463463
464464
Scalars type ops work as well. These can potentially return a *different* type of index.

0 commit comments

Comments
 (0)