Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 597dc3c

Browse files
authored
Fix docstrings for rolling methods (#733)
* Fix docstrings for rolling methods * Minor fix in docstring for rolling ctor
1 parent f5b7dba commit 597dc3c

File tree

4 files changed

+112
-15
lines changed

4 files changed

+112
-15
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2020, Intel Corporation All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
#
10+
# Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
# *****************************************************************************
26+
27+
import pandas as pd
28+
from numba import njit
29+
30+
31+
@njit
32+
def df_rolling_cov():
33+
df = pd.DataFrame({'A': [3, 3, 3, 5, 8], 'B': [-3, -3, -3, -5, -8]})
34+
other = pd.DataFrame({'A': [3, 4, 4, 4, 8], 'B': [-3, -4, -4, -4, -8]})
35+
out_df = df.rolling(4).cov(other)
36+
37+
# Expect DataFrame of
38+
# {'A': [NaN, NaN, NaN, 0.166667, 4.333333],
39+
# 'B': [NaN, NaN, NaN, 0.166667, 4.333333]}
40+
return out_df
41+
42+
43+
print(df_rolling_cov())
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2020, Intel Corporation All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
#
10+
# Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
# *****************************************************************************
26+
27+
import pandas as pd
28+
from numba import njit
29+
30+
31+
@njit
32+
def df_rolling_sum():
33+
df = pd.DataFrame({'A': [4, 3, 5, 2, 6], 'B': [-4, -3, -5, -2, -6]})
34+
out_df = df.rolling(3).sum()
35+
36+
# Expect DataFrame of
37+
# {'A': [NaN, NaN, 12.0, 10.0, 13.0], 'B': [NaN, NaN, -12.0, -10.0, -13.0]}
38+
return out_df
39+
40+
41+
print(df_rolling_sum())

sdc/datatypes/hpat_pandas_rolling_types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ def sdc_pandas_rolling_impl(self, window, min_periods=None, center=False,
181181
********************************************
182182
Pandas API: pandas.{ty}.rolling
183183
184+
Limitations
185+
-----------
186+
Parameters ``center``, ``win_type``, ``on``, ``axis`` and ``closed`` are supported only with default values.
187+
184188
Examples
185189
--------
186190
.. literalinclude:: ../../../examples/{ty_lower}/rolling/{ty_lower}_rolling_min.py

sdc/datatypes/hpat_pandas_series_rolling_functions.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@
6262
.. command-output:: python ./series/rolling/series_rolling_{method_name}.py
6363
:cwd: ../../../examples
6464
65+
.. literalinclude:: ../../../examples/dataframe/rolling/dataframe_rolling_{method_name}.py
66+
:language: python
67+
:lines: 27-
68+
:caption: {example_caption}
69+
:name: ex_dataframe_rolling_{method_name}
70+
71+
.. command-output:: python ./dataframe/rolling/dataframe_rolling_{method_name}.py
72+
:cwd: ../../../examples
73+
6574
.. seealso::
6675
:ref:`Series.rolling <pandas.Series.rolling>`
6776
Calling object with a Series.
@@ -1146,7 +1155,7 @@ def hpat_pandas_series_rolling_var(self, ddof=1):
11461155
Limitations
11471156
-----------
11481157
Supported ``raw`` only can be `None` or `True`. Parameters ``args``, ``kwargs`` unsupported.
1149-
Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
1158+
DataFrame/Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
11501159
""",
11511160
'extra_params':
11521161
"""
@@ -1165,13 +1174,13 @@ def hpat_pandas_series_rolling_var(self, ddof=1):
11651174
"""
11661175
Limitations
11671176
-----------
1168-
Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
1169-
Resulting Series has default index and name.
1177+
DataFrame/Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
1178+
Resulting DataFrame/Series has default index and name.
11701179
""",
11711180
'extra_params':
11721181
"""
1173-
other: :obj:`Series`
1174-
Other Series.
1182+
other: :obj:`DataFrame` or :obj:`Series`
1183+
Other DataFrame/Series.
11751184
pairwise: :obj:`bool`
11761185
Not relevant for Series.
11771186
"""
@@ -1191,13 +1200,13 @@ def hpat_pandas_series_rolling_var(self, ddof=1):
11911200
"""
11921201
Limitations
11931202
-----------
1194-
Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
1195-
Resulting Series has default index and name.
1203+
DataFrame/Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
1204+
Resulting DataFrame/Series has default index and name.
11961205
""",
11971206
'extra_params':
11981207
"""
1199-
other: :obj:`Series`
1200-
Other Series.
1208+
other: :obj:`DataFrame` or :obj:`Series`
1209+
Other DataFrame/Series.
12011210
pairwise: :obj:`bool`
12021211
Not relevant for Series.
12031212
ddof: :obj:`int`
@@ -1226,7 +1235,7 @@ def hpat_pandas_series_rolling_var(self, ddof=1):
12261235
"""
12271236
Limitations
12281237
-----------
1229-
Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
1238+
DataFrame/Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
12301239
""",
12311240
'extra_params': ''
12321241
})
@@ -1253,7 +1262,7 @@ def hpat_pandas_series_rolling_var(self, ddof=1):
12531262
Limitations
12541263
-----------
12551264
Supported ``interpolation`` only can be `'linear'`.
1256-
Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
1265+
DataFrame/Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
12571266
""",
12581267
'extra_params':
12591268
"""
@@ -1278,7 +1287,7 @@ def hpat_pandas_series_rolling_var(self, ddof=1):
12781287
"""
12791288
Limitations
12801289
-----------
1281-
Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
1290+
DataFrame/Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
12821291
""",
12831292
'extra_params':
12841293
"""
@@ -1289,12 +1298,12 @@ def hpat_pandas_series_rolling_var(self, ddof=1):
12891298

12901299
hpat_pandas_series_rolling_sum.__doc__ = hpat_pandas_series_rolling_docstring_tmpl.format(**{
12911300
'method_name': 'sum',
1292-
'example_caption': 'Calculate rolling sum of given Series.',
1301+
'example_caption': 'Calculate rolling sum',
12931302
'limitations_block':
12941303
"""
12951304
Limitations
12961305
-----------
1297-
Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
1306+
DataFrame/Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
12981307
""",
12991308
'extra_params': ''
13001309
})
@@ -1306,7 +1315,7 @@ def hpat_pandas_series_rolling_var(self, ddof=1):
13061315
"""
13071316
Limitations
13081317
-----------
1309-
Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
1318+
DataFrame/Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.
13101319
""",
13111320
'extra_params':
13121321
"""

0 commit comments

Comments
 (0)