From cf53fc43a29c7e4e66985f7ded50a6656242e32e Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Fri, 3 Apr 2020 21:10:57 +0300 Subject: [PATCH 1/3] DOC: Fixed examples in `pandas/core/window` --- ci/code_checks.sh | 4 ++ pandas/core/window/ewm.py | 35 +++++--------- pandas/core/window/expanding.py | 38 ++++++--------- pandas/core/window/rolling.py | 85 ++++++++++++--------------------- 4 files changed, 62 insertions(+), 100 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 3e9138814fbdf..875ca259f69d9 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -322,6 +322,10 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then pytest -q --doctest-modules pandas/core/tools/ RET=$(($RET + $?)) ; echo $MSG "DONE" + MSG='Doctests window' ; echo $MSG + pytest -q --doctest-modules pandas/core/window/ + RET=$(($RET + $?)) ; echo $MSG "DONE" + MSG='Doctests tseries' ; echo $MSG pytest -q --doctest-modules pandas/tseries/ RET=$(($RET + $?)) ; echo $MSG "DONE" diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index 0ec876583dcde..abfb74eddc052 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -167,33 +167,24 @@ def _constructor(self): """ Examples -------- - - >>> df = pd.DataFrame(np.random.randn(10, 3), columns=['A', 'B', 'C']) + >>> df = pd.DataFrame( + ... { + ... "A": [0.95117561, 0.632442, 0.72290796], + ... "B": [0.3740966, -1.48032596, -0.47270373], + ... "C": [0.39592762, 0.73835624, -0.06817024], + ... } + ... ) >>> df A B C - 0 -2.385977 -0.102758 0.438822 - 1 -1.004295 0.905829 -0.954544 - 2 0.735167 -0.165272 -1.619346 - 3 -0.702657 -1.340923 -0.706334 - 4 -0.246845 0.211596 -0.901819 - 5 2.463718 3.157577 -1.380906 - 6 -1.142255 2.340594 -0.039875 - 7 1.396598 -1.647453 1.677227 - 8 -0.543425 1.761277 -0.220481 - 9 -0.640505 0.289374 -1.550670 + 0 0.951176 0.374097 0.395928 + 1 0.632442 -1.480326 0.738356 + 2 0.722908 -0.472704 -0.068170 >>> df.ewm(alpha=0.5).mean() A B C - 0 -2.385977 -0.102758 0.438822 - 1 -1.464856 0.569633 -0.490089 - 2 -0.207700 0.149687 -1.135379 - 3 -0.471677 -0.645305 -0.906555 - 4 -0.355635 -0.203033 -0.904111 - 5 1.076417 1.503943 -1.146293 - 6 -0.041654 1.925562 -0.588728 - 7 0.680292 0.132049 0.548693 - 8 0.067236 0.948257 0.163353 - 9 -0.286980 0.618493 -0.694496 + 0 0.951176 0.374097 0.395928 + 1 0.738687 -0.862185 0.624213 + 2 0.729670 -0.639624 0.228566 """ ) diff --git a/pandas/core/window/expanding.py b/pandas/core/window/expanding.py index 140e0144d0a2d..5e01c8589e4f7 100644 --- a/pandas/core/window/expanding.py +++ b/pandas/core/window/expanding.py @@ -37,7 +37,8 @@ class Expanding(_Rolling_and_Expanding): Examples -------- - >>> df = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]}) + >>> df = pd.DataFrame({"B": [0, 1, 2, np.nan, 4]}) + >>> df B 0 0.0 1 1.0 @@ -98,33 +99,24 @@ def _get_window(self, other=None, **kwargs): """ Examples -------- - - >>> df = pd.DataFrame(np.random.randn(10, 3), columns=['A', 'B', 'C']) + >>> df = pd.DataFrame( + ... { + ... "A": [0.95117561, 0.632442, 0.72290796], + ... "B": [0.3740966, -1.48032596, -0.47270373], + ... "C": [0.39592762, 0.73835624, -0.06817024], + ... } + ... ) >>> df A B C - 0 -2.385977 -0.102758 0.438822 - 1 -1.004295 0.905829 -0.954544 - 2 0.735167 -0.165272 -1.619346 - 3 -0.702657 -1.340923 -0.706334 - 4 -0.246845 0.211596 -0.901819 - 5 2.463718 3.157577 -1.380906 - 6 -1.142255 2.340594 -0.039875 - 7 1.396598 -1.647453 1.677227 - 8 -0.543425 1.761277 -0.220481 - 9 -0.640505 0.289374 -1.550670 + 0 0.951176 0.374097 0.395928 + 1 0.632442 -1.480326 0.738356 + 2 0.722908 -0.472704 -0.068170 >>> df.ewm(alpha=0.5).mean() A B C - 0 -2.385977 -0.102758 0.438822 - 1 -1.464856 0.569633 -0.490089 - 2 -0.207700 0.149687 -1.135379 - 3 -0.471677 -0.645305 -0.906555 - 4 -0.355635 -0.203033 -0.904111 - 5 1.076417 1.503943 -1.146293 - 6 -0.041654 1.925562 -0.588728 - 7 0.680292 0.132049 0.548693 - 8 0.067236 0.948257 0.163353 - 9 -0.286980 0.618493 -0.694496 + 0 0.951176 0.374097 0.395928 + 1 0.738687 -0.862185 0.624213 + 2 0.729670 -0.639624 0.228566 """ ) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index dc8cf839d0bcb..4ed9408da7ffb 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1039,33 +1039,24 @@ def _get_window( """ Examples -------- - - >>> df = pd.DataFrame(np.random.randn(10, 3), columns=['A', 'B', 'C']) + >>> df = pd.DataFrame( + ... { + ... "A": [0.95117561, 0.632442, 0.72290796], + ... "B": [0.3740966, -1.48032596, -0.47270373], + ... "C": [0.39592762, 0.73835624, -0.06817024], + ... } + ... ) >>> df A B C - 0 -2.385977 -0.102758 0.438822 - 1 -1.004295 0.905829 -0.954544 - 2 0.735167 -0.165272 -1.619346 - 3 -0.702657 -1.340923 -0.706334 - 4 -0.246845 0.211596 -0.901819 - 5 2.463718 3.157577 -1.380906 - 6 -1.142255 2.340594 -0.039875 - 7 1.396598 -1.647453 1.677227 - 8 -0.543425 1.761277 -0.220481 - 9 -0.640505 0.289374 -1.550670 - - >>> df.rolling(3, win_type='boxcar').agg('mean') + 0 0.951176 0.374097 0.395928 + 1 0.632442 -1.480326 0.738356 + 2 0.722908 -0.472704 -0.068170 + + >>> df.rolling(3, win_type="boxcar").agg("mean") A B C 0 NaN NaN NaN 1 NaN NaN NaN - 2 -0.885035 0.212600 -0.711689 - 3 -0.323928 -0.200122 -1.093408 - 4 -0.071445 -0.431533 -1.075833 - 5 0.504739 0.676083 -0.996353 - 6 0.358206 1.903256 -0.774200 - 7 0.906020 1.283573 0.085482 - 8 -0.096361 0.818139 0.472290 - 9 0.070889 0.134399 -0.031308 + 2 0.768842 -0.526311 0.355371 """ ) @@ -1904,46 +1895,30 @@ def _validate_freq(self): """ Examples -------- - - >>> df = pd.DataFrame(np.random.randn(10, 3), columns=['A', 'B', 'C']) + >>> df = pd.DataFrame( + ... { + ... "A": [0.95117561, 0.632442, 0.72290796], + ... "B": [0.3740966, -1.48032596, -0.47270373], + ... "C": [0.39592762, 0.73835624, -0.06817024], + ... } + ... ) >>> df A B C - 0 -2.385977 -0.102758 0.438822 - 1 -1.004295 0.905829 -0.954544 - 2 0.735167 -0.165272 -1.619346 - 3 -0.702657 -1.340923 -0.706334 - 4 -0.246845 0.211596 -0.901819 - 5 2.463718 3.157577 -1.380906 - 6 -1.142255 2.340594 -0.039875 - 7 1.396598 -1.647453 1.677227 - 8 -0.543425 1.761277 -0.220481 - 9 -0.640505 0.289374 -1.550670 + 0 0.951176 0.374097 0.395928 + 1 0.632442 -1.480326 0.738356 + 2 0.722908 -0.472704 -0.068170 - >>> df.rolling(3).sum() + >>> df.rolling(2).sum() A B C 0 NaN NaN NaN - 1 NaN NaN NaN - 2 -2.655105 0.637799 -2.135068 - 3 -0.971785 -0.600366 -3.280224 - 4 -0.214334 -1.294599 -3.227500 - 5 1.514216 2.028250 -2.989060 - 6 1.074618 5.709767 -2.322600 - 7 2.718061 3.850718 0.256446 - 8 -0.289082 2.454418 1.416871 - 9 0.212668 0.403198 -0.093924 - - >>> df.rolling(3).agg({'A':'sum', 'B':'min'}) + 1 1.583618 -1.106229 1.134284 + 2 1.355350 -1.953030 0.670186 + + >>> df.rolling(2).agg({"A": "sum", "B": "min"}) A B 0 NaN NaN - 1 NaN NaN - 2 -2.655105 -0.165272 - 3 -0.971785 -1.340923 - 4 -0.214334 -1.340923 - 5 1.514216 -1.340923 - 6 1.074618 0.211596 - 7 2.718061 -1.647453 - 8 -0.289082 -1.647453 - 9 0.212668 -1.647453 + 1 1.583618 -1.480326 + 2 1.355350 -1.480326 """ ) From 8fc6c0e3b4a979954eb41d3de3370fa2cdc52d4d Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Fri, 3 Apr 2020 21:37:47 +0300 Subject: [PATCH 2/3] Using simpler numbers in examples --- pandas/core/window/ewm.py | 22 +++++------- pandas/core/window/expanding.py | 22 +++++------- pandas/core/window/rolling.py | 60 +++++++++++++-------------------- 3 files changed, 40 insertions(+), 64 deletions(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index abfb74eddc052..2759280dc1d1c 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -167,24 +167,18 @@ def _constructor(self): """ Examples -------- - >>> df = pd.DataFrame( - ... { - ... "A": [0.95117561, 0.632442, 0.72290796], - ... "B": [0.3740966, -1.48032596, -0.47270373], - ... "C": [0.39592762, 0.73835624, -0.06817024], - ... } - ... ) + >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]}) >>> df - A B C - 0 0.951176 0.374097 0.395928 - 1 0.632442 -1.480326 0.738356 - 2 0.722908 -0.472704 -0.068170 + A B C + 0 1 4 7 + 1 2 5 8 + 2 3 6 9 >>> df.ewm(alpha=0.5).mean() A B C - 0 0.951176 0.374097 0.395928 - 1 0.738687 -0.862185 0.624213 - 2 0.729670 -0.639624 0.228566 + 0 1.000000 4.000000 7.000000 + 1 1.666667 4.666667 7.666667 + 2 2.428571 5.428571 8.428571 """ ) diff --git a/pandas/core/window/expanding.py b/pandas/core/window/expanding.py index 5e01c8589e4f7..146c139806bca 100644 --- a/pandas/core/window/expanding.py +++ b/pandas/core/window/expanding.py @@ -99,24 +99,18 @@ def _get_window(self, other=None, **kwargs): """ Examples -------- - >>> df = pd.DataFrame( - ... { - ... "A": [0.95117561, 0.632442, 0.72290796], - ... "B": [0.3740966, -1.48032596, -0.47270373], - ... "C": [0.39592762, 0.73835624, -0.06817024], - ... } - ... ) + >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]}) >>> df - A B C - 0 0.951176 0.374097 0.395928 - 1 0.632442 -1.480326 0.738356 - 2 0.722908 -0.472704 -0.068170 + A B C + 0 1 4 7 + 1 2 5 8 + 2 3 6 9 >>> df.ewm(alpha=0.5).mean() A B C - 0 0.951176 0.374097 0.395928 - 1 0.738687 -0.862185 0.624213 - 2 0.729670 -0.639624 0.228566 + 0 1.000000 4.000000 7.000000 + 1 1.666667 4.666667 7.666667 + 2 2.428571 5.428571 8.428571 """ ) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 4ed9408da7ffb..729e4069b1309 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1039,24 +1039,18 @@ def _get_window( """ Examples -------- - >>> df = pd.DataFrame( - ... { - ... "A": [0.95117561, 0.632442, 0.72290796], - ... "B": [0.3740966, -1.48032596, -0.47270373], - ... "C": [0.39592762, 0.73835624, -0.06817024], - ... } - ... ) + >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]}) >>> df - A B C - 0 0.951176 0.374097 0.395928 - 1 0.632442 -1.480326 0.738356 - 2 0.722908 -0.472704 -0.068170 - - >>> df.rolling(3, win_type="boxcar").agg("mean") - A B C - 0 NaN NaN NaN - 1 NaN NaN NaN - 2 0.768842 -0.526311 0.355371 + A B C + 0 1 4 7 + 1 2 5 8 + 2 3 6 9 + + >>> df.rolling(2, win_type="boxcar").agg("mean") + A B C + 0 NaN NaN NaN + 1 1.5 4.5 7.5 + 2 2.5 5.5 8.5 """ ) @@ -1895,30 +1889,24 @@ def _validate_freq(self): """ Examples -------- - >>> df = pd.DataFrame( - ... { - ... "A": [0.95117561, 0.632442, 0.72290796], - ... "B": [0.3740966, -1.48032596, -0.47270373], - ... "C": [0.39592762, 0.73835624, -0.06817024], - ... } - ... ) + >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]}) >>> df - A B C - 0 0.951176 0.374097 0.395928 - 1 0.632442 -1.480326 0.738356 - 2 0.722908 -0.472704 -0.068170 + A B C + 0 1 4 7 + 1 2 5 8 + 2 3 6 9 >>> df.rolling(2).sum() - A B C - 0 NaN NaN NaN - 1 1.583618 -1.106229 1.134284 - 2 1.355350 -1.953030 0.670186 + A B C + 0 NaN NaN NaN + 1 3.0 9.0 15.0 + 2 5.0 11.0 17.0 >>> df.rolling(2).agg({"A": "sum", "B": "min"}) - A B - 0 NaN NaN - 1 1.583618 -1.480326 - 2 1.355350 -1.480326 + A B + 0 NaN NaN + 1 3.0 4.0 + 2 5.0 5.0 """ ) From a2de389e8f0d02c2dafd74ed5484b5d6fc607acf Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Fri, 3 Apr 2020 22:20:49 +0300 Subject: [PATCH 3/3] Restarting azure