Skip to content

Commit b9ec1fc

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 533ce34 commit b9ec1fc

File tree

1 file changed

+24
-45
lines changed

1 file changed

+24
-45
lines changed

pandas/core/window/rolling.py

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from datetime import timedelta
1010
from functools import partial
1111
import inspect
12-
from textwrap import dedent
1312
from typing import (
1413
TYPE_CHECKING,
1514
Any,
@@ -30,11 +29,6 @@
3029
import pandas._libs.window.aggregations as window_aggregations
3130
from pandas.compat._optional import import_optional_dependency
3231
from pandas.errors import DataError
33-
from pandas.util._decorators import (
34-
Appender,
35-
Substitution,
36-
doc,
37-
)
3832

3933
from pandas.core.dtypes.common import (
4034
ensure_float64,
@@ -82,19 +76,6 @@
8276
flex_binary_moment,
8377
zsqrt,
8478
)
85-
from pandas.core.window.doc import (
86-
_shared_docs,
87-
create_section_header,
88-
kwargs_numeric_only,
89-
kwargs_scipy,
90-
numba_notes,
91-
template_header,
92-
template_pipe,
93-
template_returns,
94-
template_see_also,
95-
window_agg_numba_parameters,
96-
window_apply_parameters,
97-
)
9879
from pandas.core.window.numba_ import (
9980
generate_manual_numpy_nan_agg_with_axis,
10081
generate_numba_apply_func,
@@ -1348,15 +1329,15 @@ def sum(self, numeric_only: bool = False, **kwargs):
13481329
To get an instance of :class:`~pandas.core.window.rolling.Window` we need
13491330
to pass the parameter `win_type`.
13501331
1351-
>>> type(ser.rolling(2, win_type='gaussian'))
1332+
>>> type(ser.rolling(2, win_type="gaussian"))
13521333
<class 'pandas.core.window.rolling.Window'>
13531334
13541335
In order to use the `SciPy` Gaussian window we need to provide the parameters
13551336
`M` and `std`. The parameter `M` corresponds to 2 in our example.
13561337
We pass the second parameter `std` as a parameter of the following method
13571338
(`sum` in this case):
13581339
1359-
>>> ser.rolling(2, win_type='gaussian').sum(std=3)
1340+
>>> ser.rolling(2, win_type="gaussian").sum(std=3)
13601341
0 NaN
13611342
1 0.986207
13621343
2 5.917243
@@ -1408,14 +1389,14 @@ def mean(self, numeric_only: bool = False, **kwargs):
14081389
To get an instance of :class:`~pandas.core.window.rolling.Window` we need
14091390
to pass the parameter `win_type`.
14101391
1411-
>>> type(ser.rolling(2, win_type='gaussian'))
1392+
>>> type(ser.rolling(2, win_type="gaussian"))
14121393
<class 'pandas.core.window.rolling.Window'>
14131394
14141395
In order to use the `SciPy` Gaussian window we need to provide the parameters
14151396
`M` and `std`. The parameter `M` corresponds to 2 in our example.
14161397
We pass the second parameter `std` as a parameter of the following method:
14171398
1418-
>>> ser.rolling(2, win_type='gaussian').mean(std=3)
1399+
>>> ser.rolling(2, win_type="gaussian").mean(std=3)
14191400
0 NaN
14201401
1 0.5
14211402
2 3.0
@@ -1470,14 +1451,14 @@ def var(self, ddof: int = 1, numeric_only: bool = False, **kwargs):
14701451
To get an instance of :class:`~pandas.core.window.rolling.Window` we need
14711452
to pass the parameter `win_type`.
14721453
1473-
>>> type(ser.rolling(2, win_type='gaussian'))
1454+
>>> type(ser.rolling(2, win_type="gaussian"))
14741455
<class 'pandas.core.window.rolling.Window'>
14751456
14761457
In order to use the `SciPy` Gaussian window we need to provide the parameters
14771458
`M` and `std`. The parameter `M` corresponds to 2 in our example.
14781459
We pass the second parameter `std` as a parameter of the following method:
14791460
1480-
>>> ser.rolling(2, win_type='gaussian').var(std=3)
1461+
>>> ser.rolling(2, win_type="gaussian").var(std=3)
14811462
0 NaN
14821463
1 0.5
14831464
2 8.0
@@ -1525,14 +1506,14 @@ def std(self, ddof: int = 1, numeric_only: bool = False, **kwargs):
15251506
To get an instance of :class:`~pandas.core.window.rolling.Window` we need
15261507
to pass the parameter `win_type`.
15271508
1528-
>>> type(ser.rolling(2, win_type='gaussian'))
1509+
>>> type(ser.rolling(2, win_type="gaussian"))
15291510
<class 'pandas.core.window.rolling.Window'>
15301511
15311512
In order to use the `SciPy` Gaussian window we need to provide the parameters
15321513
`M` and `std`. The parameter `M` corresponds to 2 in our example.
15331514
We pass the second parameter `std` as a parameter of the following method:
15341515
1535-
>>> ser.rolling(2, win_type='gaussian').std(std=3)
1516+
>>> ser.rolling(2, win_type="gaussian").std(std=3)
15361517
0 NaN
15371518
1 0.707107
15381519
2 2.828427
@@ -2304,17 +2285,16 @@ def pipe(
23042285
23052286
>>> h = lambda x, arg2, arg3: x + 1 - arg2 * arg3
23062287
>>> g = lambda x, arg1: x * 5 / arg1
2307-
>>> f = lambda x: x ** 4
2288+
>>> f = lambda x: x**4
23082289
>>> df = pd.DataFrame({'A': [1, 2, 3, 4]},
23092290
index=pd.date_range('2012-08-02', periods=4))
2310-
>>> h(g(f(df.rolling('2D')), arg1=1), arg2=2, arg3=3) # doctest: +SKIP
2291+
>>> h(g(f(df.rolling("2D")), arg1=1), arg2=2, arg3=3) # doctest: +SKIP
23112292
23122293
You can write
23132294
2314-
>>> (df.rolling('2D')
2315-
... .pipe(f)
2316-
... .pipe(g, arg1=1)
2317-
... .pipe(h, arg2=2, arg3=3)) # doctest: +SKIP
2295+
>>> (
2296+
... df.rolling("2D").pipe(f).pipe(g, arg1=1).pipe(h, arg2=2, arg3=3)
2297+
... ) # doctest: +SKIP
23182298
23192299
which is much more readable.
23202300
@@ -2350,8 +2330,9 @@ def pipe(
23502330
Examples
23512331
--------
23522332
2353-
>>> df = pd.DataFrame({'A': [1, 2, 3, 4]},
2354-
... index=pd.date_range('2012-08-02', periods=4))
2333+
>>> df = pd.DataFrame(
2334+
... {"A": [1, 2, 3, 4]}, index=pd.date_range("2012-08-02", periods=4)
2335+
... )
23552336
>>> df
23562337
A
23572338
2012-08-02 1
@@ -2363,7 +2344,7 @@ def pipe(
23632344
2-day window's maximum and minimum
23642345
value in one pass, you can do
23652346
2366-
>>> df.rolling('2D').pipe(lambda x: x.max() - x.min())
2347+
>>> df.rolling("2D").pipe(lambda x: x.max() - x.min())
23672348
A
23682349
2012-08-02 0.0
23692350
2012-08-03 1.0
@@ -2452,7 +2433,7 @@ def sum(
24522433
24532434
For DataFrame, each sum is computed column-wise.
24542435
2455-
>>> df = pd.DataFrame({"A": s, "B": s ** 2})
2436+
>>> df = pd.DataFrame({"A": s, "B": s**2})
24562437
>>> df
24572438
A B
24582439
0 1 1
@@ -3180,14 +3161,14 @@ def quantile(
31803161
Examples
31813162
--------
31823163
>>> s = pd.Series([1, 2, 3, 4])
3183-
>>> s.rolling(2).quantile(.4, interpolation='lower')
3164+
>>> s.rolling(2).quantile(0.4, interpolation="lower")
31843165
0 NaN
31853166
1 1.0
31863167
2 2.0
31873168
3 3.0
31883169
dtype: float64
31893170
3190-
>>> s.rolling(2).quantile(.4, interpolation='midpoint')
3171+
>>> s.rolling(2).quantile(0.4, interpolation="midpoint")
31913172
0 NaN
31923173
1 1.5
31933174
2 2.5
@@ -3478,18 +3459,16 @@ def corr(
34783459
The below example shows a similar rolling calculation on a
34793460
DataFrame using the pairwise option.
34803461
3481-
>>> matrix = np.array([[51., 35.],
3482-
... [49., 30.],
3483-
... [47., 32.],
3484-
... [46., 31.],
3485-
... [50., 36.]])
3462+
>>> matrix = np.array(
3463+
... [[51.0, 35.0], [49.0, 30.0], [47.0, 32.0], [46.0, 31.0], [50.0, 36.0]]
3464+
... )
34863465
>>> np.corrcoef(matrix[:-1, 0], matrix[:-1, 1])
34873466
array([[1. , 0.6263001],
34883467
[0.6263001, 1. ]])
34893468
>>> np.corrcoef(matrix[1:, 0], matrix[1:, 1])
34903469
array([[1. , 0.55536811],
34913470
[0.55536811, 1. ]])
3492-
>>> df = pd.DataFrame(matrix, columns=['X', 'Y'])
3471+
>>> df = pd.DataFrame(matrix, columns=["X", "Y"])
34933472
>>> df
34943473
X Y
34953474
0 51.0 35.0

0 commit comments

Comments
 (0)