From 77f2a2b66303ee33d6db2169277cccbc351be5f8 Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Mon, 14 May 2018 17:09:21 -0400 Subject: [PATCH 01/16] added an example to shift --- pandas/core/generic.py | 56 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 9e4eda1bc4dc7..e7cf067ad1c57 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7806,7 +7806,61 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, If freq is specified then the index values are shifted but the data is not realigned. That is, use freq if you would like to extend the index when shifting and preserve the original data. - + + Examples + -------- + Compute the difference between a column in a dataframe and its shifted version + + >>> data = pd.DataFrame({'mydate': [pd.to_datetime('2016-06-06'), + ... pd.to_datetime('2016-06-08'), + ... pd.to_datetime('2016-06-09'), + ... pd.to_datetime('2016-06-10'), + ... pd.to_datetime('2016-06-12'), + ... pd.to_datetime('2016-06-13')], + ... 'myvalue': [1, 2, 3, 4, 5, 6], + ... 'group': ['A', 'A', 'A', 'B', 'B', 'B']}) + + >>> data.set_index('mydate', inplace=True) + >>> data + myvalue group + mydate + 2016-06-06 1 A + 2016-06-08 2 A + 2016-06-09 3 A + 2016-06-10 4 B + 2016-06-12 5 B + 2016-06-13 6 B + + For the groups compute the difference between current *myvalue* and *myvalue* shifted forward by 1 day + + >>> result = data.groupby('group').myvalue.apply(lambda x: x - x.shift(1, pd.Timedelta('1 days'))) + >>> result + group mydate + A 2016-06-06 NaN + 2016-06-07 NaN + 2016-06-08 NaN + 2016-06-09 1.0 + 2016-06-10 NaN + B 2016-06-10 NaN + 2016-06-11 NaN + 2016-06-12 NaN + 2016-06-13 1.0 + 2016-06-14 NaN + Name: myvalue, dtype: float64 + + Merge result as a column named *delta* to the original data + + >>> result.name = 'delta' + >>> data.reset_index().merge(result.reset_index(), how='left', on=['mydate', 'group']).set_index('mydate') + myvalue group delta + mydate + 2016-06-06 1 A NaN + 2016-06-08 2 A NaN + 2016-06-09 3 A 1.0 + 2016-06-10 4 B NaN + 2016-06-12 5 B NaN + 2016-06-13 6 B 1.0 + Returns ------- shifted : %(klass)s From c935896386de4c0184583e8ca6bce60991c70197 Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Mon, 14 May 2018 17:33:05 -0400 Subject: [PATCH 02/16] fixing pep8 errors --- pandas/core/generic.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e7cf067ad1c57..7422f68b0bfba 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7806,11 +7806,12 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, If freq is specified then the index values are shifted but the data is not realigned. That is, use freq if you would like to extend the index when shifting and preserve the original data. - + Examples -------- - Compute the difference between a column in a dataframe and its shifted version - + Compute the difference between a column in a dataframe and + its shifted version + >>> data = pd.DataFrame({'mydate': [pd.to_datetime('2016-06-06'), ... pd.to_datetime('2016-06-08'), ... pd.to_datetime('2016-06-09'), @@ -7830,10 +7831,12 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, 2016-06-10 4 B 2016-06-12 5 B 2016-06-13 6 B - - For the groups compute the difference between current *myvalue* and *myvalue* shifted forward by 1 day - - >>> result = data.groupby('group').myvalue.apply(lambda x: x - x.shift(1, pd.Timedelta('1 days'))) + + For the groups compute the difference between current *myvalue* and + *myvalue* shifted forward by 1 day + + >>> result = data.groupby('group').myvalue.apply( + ... lambda x: x - x.shift(1, pd.Timedelta('1 days'))) >>> result group mydate A 2016-06-06 NaN @@ -7847,11 +7850,14 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, 2016-06-13 1.0 2016-06-14 NaN Name: myvalue, dtype: float64 - + Merge result as a column named *delta* to the original data - + >>> result.name = 'delta' - >>> data.reset_index().merge(result.reset_index(), how='left', on=['mydate', 'group']).set_index('mydate') + >>> data.reset_index().merge( + ... result.reset_index(), + ... how='left', + ... on=['mydate', 'group']).set_index('mydate') myvalue group delta mydate 2016-06-06 1 A NaN @@ -7860,7 +7866,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, 2016-06-10 4 B NaN 2016-06-12 5 B NaN 2016-06-13 6 B 1.0 - + Returns ------- shifted : %(klass)s From 206b2daab11a6bb8d791369c5e05e226dd8b318b Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Sat, 2 Jun 2018 18:02:38 +0100 Subject: [PATCH 03/16] making changes per feedback --- pandas/core/generic.py | 86 ++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 46 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 7422f68b0bfba..5a8f68e78a81c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7809,56 +7809,50 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, Examples -------- - Compute the difference between a column in a dataframe and - its shifted version - - >>> data = pd.DataFrame({'mydate': [pd.to_datetime('2016-06-06'), - ... pd.to_datetime('2016-06-08'), - ... pd.to_datetime('2016-06-09'), - ... pd.to_datetime('2016-06-10'), - ... pd.to_datetime('2016-06-12'), - ... pd.to_datetime('2016-06-13')], - ... 'myvalue': [1, 2, 3, 4, 5, 6], - ... 'group': ['A', 'A', 'A', 'B', 'B', 'B']}) - - >>> data.set_index('mydate', inplace=True) + Compute the difference between a column in a dataframe with grouped data, and + its shifted version. + + >>> data = pd.DataFrame({'myvalue': [1, 2, 3, 4, 5, 6], + ... 'group': ['A', 'A', 'A', 'B', 'B', 'B']}, + ... index=pd.DatetimeIndex(['2016-06-06', + ... '2016-06-08', + ... '2016-06-09', + ... '2016-06-10', + ... '2016-06-12', + ... '2016-06-13'], name='mydate')) + >>> data - myvalue group - mydate - 2016-06-06 1 A - 2016-06-08 2 A - 2016-06-09 3 A - 2016-06-10 4 B - 2016-06-12 5 B - 2016-06-13 6 B - - For the groups compute the difference between current *myvalue* and - *myvalue* shifted forward by 1 day - - >>> result = data.groupby('group').myvalue.apply( - ... lambda x: x - x.shift(1, pd.Timedelta('1 days'))) + myvalue group + mydate + 2016-06-06 1 A + 2016-06-08 2 A + 2016-06-09 3 A + 2016-06-10 4 B + 2016-06-12 5 B + 2016-06-13 6 B + + For the groups compute the difference between current `myvalue` and + `myvalue` shifted forward by 1 day + + >>> result = data.groupby('group').myvalue.apply(lambda x: x - x.shift(1, pd.Timedelta('1 days'))) >>> result - group mydate - A 2016-06-06 NaN - 2016-06-07 NaN - 2016-06-08 NaN - 2016-06-09 1.0 - 2016-06-10 NaN - B 2016-06-10 NaN - 2016-06-11 NaN - 2016-06-12 NaN - 2016-06-13 1.0 - 2016-06-14 NaN - Name: myvalue, dtype: float64 - - Merge result as a column named *delta* to the original data + group mydate + A 2016-06-06 NaN + 2016-06-07 NaN + 2016-06-08 NaN + 2016-06-09 1.0 + 2016-06-10 NaN + B 2016-06-10 NaN + 2016-06-11 NaN + 2016-06-12 NaN + 2016-06-13 1.0 + 2016-06-14 NaN + Name: myvalue, dtype: float64 + + Merge result as a column named `delta` to the original data >>> result.name = 'delta' - >>> data.reset_index().merge( - ... result.reset_index(), - ... how='left', - ... on=['mydate', 'group']).set_index('mydate') - myvalue group delta + >>> pd.merge(data, result.to_frame(), on=['mydate', 'group']) mydate 2016-06-06 1 A NaN 2016-06-08 2 A NaN From c31d1a170252ba6187cb154cb0450b63de2b0dec Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Sat, 2 Jun 2018 18:33:21 +0100 Subject: [PATCH 04/16] fixing pep8 errors --- pandas/core/generic.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 5a8f68e78a81c..de9a664fb7b26 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7790,12 +7790,12 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, errors=errors) _shared_docs['shift'] = (""" - Shift index by desired number of periods with an optional time freq + Shift index by desired number of periods with an optional time freq. Parameters ---------- periods : int - Number of periods to move, can be positive or negative + Number of periods to move, can be positive or negative. freq : DateOffset, timedelta, or time rule string, optional Increment to use from the tseries module or time rule (e.g. 'EOM'). See Notes. @@ -7809,8 +7809,8 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, Examples -------- - Compute the difference between a column in a dataframe with grouped data, and - its shifted version. + Compute the difference between a column in a dataframe + with grouped data, and its shifted version. >>> data = pd.DataFrame({'myvalue': [1, 2, 3, 4, 5, 6], ... 'group': ['A', 'A', 'A', 'B', 'B', 'B']}, @@ -7819,10 +7819,11 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, ... '2016-06-09', ... '2016-06-10', ... '2016-06-12', - ... '2016-06-13'], name='mydate')) + ... '2016-06-13'], + ... name='mydate')) >>> data - myvalue group + myvalue group mydate 2016-06-06 1 A 2016-06-08 2 A @@ -7834,7 +7835,8 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, For the groups compute the difference between current `myvalue` and `myvalue` shifted forward by 1 day - >>> result = data.groupby('group').myvalue.apply(lambda x: x - x.shift(1, pd.Timedelta('1 days'))) + >>> result = data.groupby('group').myvalue.apply( + ... lambda x: x - x.shift(1, pd.Timedelta('1 days'))) >>> result group mydate A 2016-06-06 NaN @@ -7853,6 +7855,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, >>> result.name = 'delta' >>> pd.merge(data, result.to_frame(), on=['mydate', 'group']) + myvalue group delta mydate 2016-06-06 1 A NaN 2016-06-08 2 A NaN From 73a640f406cb3c3181e03d024022006137b208af Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Sat, 2 Jun 2018 18:37:05 +0100 Subject: [PATCH 05/16] fix trailing whitespace --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index de9a664fb7b26..6c8dab2079e90 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7823,7 +7823,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, ... name='mydate')) >>> data - myvalue group + myvalue group mydate 2016-06-06 1 A 2016-06-08 2 A From de0b7a1cb47072d76e7fa25a3e35ddf22f7fc384 Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Thu, 28 Jun 2018 23:40:12 +0100 Subject: [PATCH 06/16] WIP: adding more detail in docstring --- pandas/core/generic.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a9867b86050fb..212171d92cc2f 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7834,6 +7834,28 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, For the groups compute the difference between current `myvalue` and `myvalue` shifted forward by 1 day + If the dataframe is shifted without passing a freq argument than the + values simply move down + + >>> data[data.group=='A'].myvalue.shift(1) + mydate + 2016-06-06 NaN + 2016-06-08 1.0 + 2016-06-09 2.0 + Name: myvalue, dtype: float64 + + What we want however, is to shift myvalue forward by one day in order + to compute the difference. + + >>> data[data.group=='A'].myvalue.shift(1, freq=pd.Timedelta('1 days')) + mydate + 2016-06-07 1 + 2016-06-09 2 + 2016-06-10 3 + Name: myvalue, dtype: int64 + + After considering the grouping we can calculate the difference + as follows >>> result = data.groupby('group').myvalue.apply( ... lambda x: x - x.shift(1, pd.Timedelta('1 days'))) From a9550fa6afff375cccf45ea79fd84cae9450972f Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Sun, 1 Jul 2018 08:38:14 +0100 Subject: [PATCH 07/16] displaying difference between shift with/without freq --- pandas/core/generic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a38995fafe93c..be5ada0ac84b2 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7836,7 +7836,8 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, 2016-06-13 6 B For the groups compute the difference between current `myvalue` and - `myvalue` shifted forward by 1 day + `myvalue` shifted forward by 1 day. + If the dataframe is shifted without passing a freq argument than the values simply move down From ab4e2f57ff454128ac5f34d1cf4ca54a5652ef91 Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Sun, 22 Jul 2018 19:51:44 +0100 Subject: [PATCH 08/16] wip: updating docstring --- pandas/core/generic.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a196e66c73ed0..2bc3cdb5feff9 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7965,8 +7965,6 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, Examples -------- - Compute the difference between a column in a dataframe - with grouped data, and its shifted version. >>> data = pd.DataFrame({'myvalue': [1, 2, 3, 4, 5, 6], ... 'group': ['A', 'A', 'A', 'B', 'B', 'B']}, From 5bcae816e597973d1214298564f7dbbadeee5af2 Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Sun, 22 Jul 2018 20:29:20 +0100 Subject: [PATCH 09/16] wip: updating docstring --- pandas/core/generic.py | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 3ee043f9144a2..fdfb7a9b69aa5 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8032,7 +8032,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, Examples -------- - >>> data = pd.DataFrame({'myvalue': [1, 2, 3, 4, 5, 6], + >>> df = pd.DataFrame({'myvalue': [1, 2, 3, 4, 5, 6], ... 'group': ['A', 'A', 'A', 'B', 'B', 'B']}, ... index=pd.DatetimeIndex(['2016-06-06', ... '2016-06-08', @@ -8042,7 +8042,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, ... '2016-06-13'], ... name='mydate')) - >>> data + >>> df myvalue group mydate 2016-06-06 1 A @@ -8055,31 +8055,40 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, For the groups compute the difference between current `myvalue` and `myvalue` shifted forward by 1 day. - If the dataframe is shifted without passing a freq argument than the - values simply move down + If `myvalue` is shifted then the values will simply move down. - >>> data[data.group=='A'].myvalue.shift(1) + >>> df.myvalue.shift(1) mydate 2016-06-06 NaN 2016-06-08 1.0 2016-06-09 2.0 + 2016-06-10 3.0 + 2016-06-12 4.0 + 2016-06-13 5.0 Name: myvalue, dtype: float64 - What we want however, is to shift myvalue forward by one day in order - to compute the difference. + We only want to shift myvalue forward by one day before computing + the difference. We can do this by reindexing and filling the groups + first - >>> data[data.group=='A'].myvalue.shift(1, freq=pd.Timedelta('1 days')) - mydate - 2016-06-07 1 - 2016-06-09 2 - 2016-06-10 3 - Name: myvalue, dtype: int64 + >>> date_range = pd.date_range(df.index.min(), df.index.max()) + >>> df = df.reindex(date_range) + >>> df['group'] = df['group'].ffill() + >>> df + group myvalue + 2016-06-06 A 1.0 + 2016-06-07 A NaN + 2016-06-08 A 2.0 + 2016-06-09 A 3.0 + 2016-06-10 B 4.0 + 2016-06-11 B NaN + 2016-06-12 B 5.0 + 2016-06-13 B 6.0 After considering the grouping we can calculate the difference as follows - >>> result = data.groupby('group').myvalue.apply( - ... lambda x: x - x.shift(1, pd.Timedelta('1 days'))) + >>> result = df['myvalue'] - df.groupby('group')['myvalue'].shift(1) >>> result group mydate A 2016-06-06 NaN From 17f55d544d9f0fd3dd9d3ed9d6a039d08cbbaae1 Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Sun, 22 Jul 2018 21:35:48 +0100 Subject: [PATCH 10/16] wip: updating docstring --- pandas/core/generic.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index fdfb7a9b69aa5..21049c8195bbc 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8103,18 +8103,19 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, 2016-06-14 NaN Name: myvalue, dtype: float64 - Merge result as a column named `delta` to the original data + Concatenate result as a column named `delta` to the original data >>> result.name = 'delta' - >>> pd.merge(data, result.to_frame(), on=['mydate', 'group']) - myvalue group delta - mydate - 2016-06-06 1 A NaN - 2016-06-08 2 A NaN - 2016-06-09 3 A 1.0 - 2016-06-10 4 B NaN - 2016-06-12 5 B NaN - 2016-06-13 6 B 1.0 + >>> pd.concat([df, result], axis=1) + group myvalue delta + 2016-06-06 A 1.0 NaN + 2016-06-07 A NaN NaN + 2016-06-08 A 2.0 NaN + 2016-06-09 A 3.0 1.0 + 2016-06-10 B 4.0 NaN + 2016-06-11 B NaN NaN + 2016-06-12 B 5.0 NaN + 2016-06-13 B 6.0 1.0 Returns ------- From 4dd276a509839cebf282b98bfd856499d022ad20 Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Sun, 22 Jul 2018 21:48:26 +0100 Subject: [PATCH 11/16] Docstring updated --- pandas/core/generic.py | 63 ++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 21049c8195bbc..87ac0a45077a6 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8032,8 +8032,8 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, Examples -------- - >>> df = pd.DataFrame({'myvalue': [1, 2, 3, 4, 5, 6], - ... 'group': ['A', 'A', 'A', 'B', 'B', 'B']}, + >>> df = pd.DataFrame({'group': ['A', 'A', 'A', 'B', 'B', 'B'], + ... 'myvalue': [1, 2, 3, 4, 5, 6]}, ... index=pd.DatetimeIndex(['2016-06-06', ... '2016-06-08', ... '2016-06-09', @@ -8043,14 +8043,14 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, ... name='mydate')) >>> df - myvalue group - mydate - 2016-06-06 1 A - 2016-06-08 2 A - 2016-06-09 3 A - 2016-06-10 4 B - 2016-06-12 5 B - 2016-06-13 6 B + group myvalue + mydate + 2016-06-06 A 1 + 2016-06-08 A 2 + 2016-06-09 A 3 + 2016-06-10 B 4 + 2016-06-12 B 5 + 2016-06-13 B 6 For the groups compute the difference between current `myvalue` and `myvalue` shifted forward by 1 day. @@ -8067,7 +8067,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, 2016-06-13 5.0 Name: myvalue, dtype: float64 - We only want to shift myvalue forward by one day before computing + We only want to shift `myvalue` forward by one day before computing the difference. We can do this by reindexing and filling the groups first @@ -8075,7 +8075,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, >>> df = df.reindex(date_range) >>> df['group'] = df['group'].ffill() >>> df - group myvalue + group myvalue 2016-06-06 A 1.0 2016-06-07 A NaN 2016-06-08 A 2.0 @@ -8090,32 +8090,29 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, >>> result = df['myvalue'] - df.groupby('group')['myvalue'].shift(1) >>> result - group mydate - A 2016-06-06 NaN - 2016-06-07 NaN - 2016-06-08 NaN - 2016-06-09 1.0 - 2016-06-10 NaN - B 2016-06-10 NaN - 2016-06-11 NaN - 2016-06-12 NaN - 2016-06-13 1.0 - 2016-06-14 NaN - Name: myvalue, dtype: float64 + 2016-06-06 NaN + 2016-06-07 NaN + 2016-06-08 NaN + 2016-06-09 1.0 + 2016-06-10 NaN + 2016-06-11 NaN + 2016-06-12 NaN + 2016-06-13 1.0 + Freq: D, Name: myvalue, dtype: float64 Concatenate result as a column named `delta` to the original data >>> result.name = 'delta' >>> pd.concat([df, result], axis=1) - group myvalue delta - 2016-06-06 A 1.0 NaN - 2016-06-07 A NaN NaN - 2016-06-08 A 2.0 NaN - 2016-06-09 A 3.0 1.0 - 2016-06-10 B 4.0 NaN - 2016-06-11 B NaN NaN - 2016-06-12 B 5.0 NaN - 2016-06-13 B 6.0 1.0 + group myvalue delta + 2016-06-06 A 1.0 NaN + 2016-06-07 A NaN NaN + 2016-06-08 A 2.0 NaN + 2016-06-09 A 3.0 1.0 + 2016-06-10 B 4.0 NaN + 2016-06-11 B NaN NaN + 2016-06-12 B 5.0 NaN + 2016-06-13 B 6.0 1.0 Returns ------- From 0b4f41b27506159236fbb315bf9cdde571d4cd68 Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Sun, 22 Jul 2018 21:53:11 +0100 Subject: [PATCH 12/16] fixing pep8 issues --- pandas/core/generic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 87ac0a45077a6..9bcb44e2b97be 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8044,7 +8044,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, >>> df group myvalue - mydate + mydate 2016-06-06 A 1 2016-06-08 A 2 2016-06-09 A 3 @@ -8055,7 +8055,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, For the groups compute the difference between current `myvalue` and `myvalue` shifted forward by 1 day. - If `myvalue` is shifted then the values will simply move down. + If `myvalue` is shifted then the values will simply move down. >>> df.myvalue.shift(1) mydate @@ -8110,7 +8110,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, 2016-06-08 A 2.0 NaN 2016-06-09 A 3.0 1.0 2016-06-10 B 4.0 NaN - 2016-06-11 B NaN NaN + 2016-06-11 B NaN NaN 2016-06-12 B 5.0 NaN 2016-06-13 B 6.0 1.0 From 7c15b08e34e38cf16b293f64e6cc3b05ecf19d9e Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Sun, 22 Jul 2018 22:05:26 +0100 Subject: [PATCH 13/16] fix whitespace in frames --- pandas/core/generic.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 9bcb44e2b97be..2517d74324d52 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8075,15 +8075,15 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, >>> df = df.reindex(date_range) >>> df['group'] = df['group'].ffill() >>> df - group myvalue - 2016-06-06 A 1.0 - 2016-06-07 A NaN - 2016-06-08 A 2.0 - 2016-06-09 A 3.0 - 2016-06-10 B 4.0 - 2016-06-11 B NaN - 2016-06-12 B 5.0 - 2016-06-13 B 6.0 + group myvalue + 2016-06-06 A 1.0 + 2016-06-07 A NaN + 2016-06-08 A 2.0 + 2016-06-09 A 3.0 + 2016-06-10 B 4.0 + 2016-06-11 B NaN + 2016-06-12 B 5.0 + 2016-06-13 B 6.0 After considering the grouping we can calculate the difference as follows @@ -8104,15 +8104,15 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, >>> result.name = 'delta' >>> pd.concat([df, result], axis=1) - group myvalue delta - 2016-06-06 A 1.0 NaN - 2016-06-07 A NaN NaN - 2016-06-08 A 2.0 NaN - 2016-06-09 A 3.0 1.0 - 2016-06-10 B 4.0 NaN - 2016-06-11 B NaN NaN - 2016-06-12 B 5.0 NaN - 2016-06-13 B 6.0 1.0 + group myvalue delta + 2016-06-06 A 1.0 NaN + 2016-06-07 A NaN NaN + 2016-06-08 A 2.0 NaN + 2016-06-09 A 3.0 1.0 + 2016-06-10 B 4.0 NaN + 2016-06-11 B NaN NaN + 2016-06-12 B 5.0 NaN + 2016-06-13 B 6.0 1.0 Returns ------- From 950cc2ece810fee25d7c537f9eae41e152ca90aa Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Sun, 22 Jul 2018 22:17:18 +0100 Subject: [PATCH 14/16] fixing whitespace --- pandas/core/generic.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 2517d74324d52..3764323962aca 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8075,16 +8075,16 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, >>> df = df.reindex(date_range) >>> df['group'] = df['group'].ffill() >>> df - group myvalue - 2016-06-06 A 1.0 - 2016-06-07 A NaN - 2016-06-08 A 2.0 - 2016-06-09 A 3.0 - 2016-06-10 B 4.0 - 2016-06-11 B NaN - 2016-06-12 B 5.0 - 2016-06-13 B 6.0 - + group myvalue + 2016-06-06 A 1.0 + 2016-06-07 A NaN + 2016-06-08 A 2.0 + 2016-06-09 A 3.0 + 2016-06-10 B 4.0 + 2016-06-11 B NaN + 2016-06-12 B 5.0 + 2016-06-13 B 6.0 + After considering the grouping we can calculate the difference as follows @@ -8104,15 +8104,15 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, >>> result.name = 'delta' >>> pd.concat([df, result], axis=1) - group myvalue delta - 2016-06-06 A 1.0 NaN - 2016-06-07 A NaN NaN - 2016-06-08 A 2.0 NaN - 2016-06-09 A 3.0 1.0 - 2016-06-10 B 4.0 NaN - 2016-06-11 B NaN NaN - 2016-06-12 B 5.0 NaN - 2016-06-13 B 6.0 1.0 + group myvalue delta + 2016-06-06 A 1.0 NaN + 2016-06-07 A NaN NaN + 2016-06-08 A 2.0 NaN + 2016-06-09 A 3.0 1.0 + 2016-06-10 B 4.0 NaN + 2016-06-11 B NaN NaN + 2016-06-12 B 5.0 NaN + 2016-06-13 B 6.0 1.0 Returns ------- From 9ec5ed72745cb6d85f2fb097ca14934faba46b28 Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Sun, 22 Jul 2018 23:02:18 +0100 Subject: [PATCH 15/16] fixing whitespace --- pandas/core/generic.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 3764323962aca..f121f6cd586e5 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8075,7 +8075,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, >>> df = df.reindex(date_range) >>> df['group'] = df['group'].ffill() >>> df - group myvalue + group myvalue 2016-06-06 A 1.0 2016-06-07 A NaN 2016-06-08 A 2.0 @@ -8104,15 +8104,15 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, >>> result.name = 'delta' >>> pd.concat([df, result], axis=1) - group myvalue delta - 2016-06-06 A 1.0 NaN - 2016-06-07 A NaN NaN - 2016-06-08 A 2.0 NaN - 2016-06-09 A 3.0 1.0 - 2016-06-10 B 4.0 NaN - 2016-06-11 B NaN NaN - 2016-06-12 B 5.0 NaN - 2016-06-13 B 6.0 1.0 + group myvalue delta + 2016-06-06 A 1.0 NaN + 2016-06-07 A NaN NaN + 2016-06-08 A 2.0 NaN + 2016-06-09 A 3.0 1.0 + 2016-06-10 B 4.0 NaN + 2016-06-11 B NaN NaN + 2016-06-12 B 5.0 NaN + 2016-06-13 B 6.0 1.0 Returns ------- From 888b97b7b775dab23f4ff3363b533f074909e5a1 Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Sun, 22 Jul 2018 23:03:50 +0100 Subject: [PATCH 16/16] fixing pep8 errors --- pandas/core/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f121f6cd586e5..84595153103c7 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8084,7 +8084,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, 2016-06-11 B NaN 2016-06-12 B 5.0 2016-06-13 B 6.0 - + After considering the grouping we can calculate the difference as follows @@ -8111,7 +8111,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, 2016-06-09 A 3.0 1.0 2016-06-10 B 4.0 NaN 2016-06-11 B NaN NaN - 2016-06-12 B 5.0 NaN + 2016-06-12 B 5.0 NaN 2016-06-13 B 6.0 1.0 Returns