From dd2bd670238e4801d7f24677e4058f5fc5de6e22 Mon Sep 17 00:00:00 2001 From: "karmanya.aggarwal" Date: Tue, 9 Oct 2018 06:29:13 +0530 Subject: [PATCH 1/8] DOC: update the pandas.DateTimeArrayMixin.is_month_start docstring --- pandas/core/arrays/datetimes.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 7daaa8de1734f..bec4b4a898a74 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1011,6 +1011,30 @@ def date(self): 'is_month_start', 'is_month_start', "Logical indicating if first day of month (defined by frequency)") + """ + Indicates whether the date is the first day of the month. + Returns + ------- + Series of bool. + + See Also + -------- + is_month_end : Return a boolean indicating whether the date is + the last day of the month. + Examples + -------- + >>> s = pd.Series(pd.date_range("2018-02-27", periods=3)) + >>> s + 0 2018-02-27 + 1 2018-02-28 + 2 2018-03-01 + dtype: datetime64[ns] + >>> s.dt.is_month_start + 0 False + 1 False + 2 True + dtype: bool + """) is_month_end = _field_accessor( 'is_month_end', 'is_month_end', From 6f92de4b465ba4718383f2543085ef0aa05eeda0 Mon Sep 17 00:00:00 2001 From: "karmanya.aggarwal" Date: Tue, 9 Oct 2018 06:41:21 +0530 Subject: [PATCH 2/8] fixed unexpected indent + removed trailing ) --- pandas/core/arrays/datetimes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index bec4b4a898a74..d361db1088fda 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1011,7 +1011,7 @@ def date(self): 'is_month_start', 'is_month_start', "Logical indicating if first day of month (defined by frequency)") - """ + """ Indicates whether the date is the first day of the month. Returns ------- @@ -1034,7 +1034,7 @@ def date(self): 1 False 2 True dtype: bool - """) + """ is_month_end = _field_accessor( 'is_month_end', 'is_month_end', From 108535a7fedbb92b8ddfb0ee17a8d6891d5fe58a Mon Sep 17 00:00:00 2001 From: "karmanya.aggarwal" Date: Wed, 10 Oct 2018 13:58:44 +0530 Subject: [PATCH 3/8] formatting issues fixes --- pandas/core/arrays/datetimes.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index d361db1088fda..92cea2e145e24 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1013,14 +1013,18 @@ def date(self): "Logical indicating if first day of month (defined by frequency)") """ Indicates whether the date is the first day of the month. + Returns ------- - Series of bool. + Series of bool + Series of boolean values indicating whether the date is the first + day of the month See Also -------- is_month_end : Return a boolean indicating whether the date is the last day of the month. + Examples -------- >>> s = pd.Series(pd.date_range("2018-02-27", periods=3)) From 11fe3008c93e6f706ece828e0afa14002fa1946a Mon Sep 17 00:00:00 2001 From: "karmanya.aggarwal" Date: Thu, 11 Oct 2018 11:48:59 +0530 Subject: [PATCH 4/8] added a period --- pandas/core/arrays/datetimes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 92cea2e145e24..6c6c468063bd0 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1018,7 +1018,7 @@ def date(self): ------- Series of bool Series of boolean values indicating whether the date is the first - day of the month + day of the month. See Also -------- From 4a0c57270c968e8072d4b910ee930f59654711d1 Mon Sep 17 00:00:00 2001 From: "karmanya.aggarwal" Date: Thu, 11 Oct 2018 12:48:42 +0530 Subject: [PATCH 5/8] fixed flake8 --- pandas/core/arrays/datetimes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 6c6c468063bd0..44cc903f77486 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1013,7 +1013,7 @@ def date(self): "Logical indicating if first day of month (defined by frequency)") """ Indicates whether the date is the first day of the month. - + Returns ------- Series of bool @@ -1024,7 +1024,7 @@ def date(self): -------- is_month_end : Return a boolean indicating whether the date is the last day of the month. - + Examples -------- >>> s = pd.Series(pd.date_range("2018-02-27", periods=3)) From 38268f226efc0685852f4538ee4f78efd805f688 Mon Sep 17 00:00:00 2001 From: "karmanya.aggarwal" Date: Thu, 11 Oct 2018 13:02:58 +0530 Subject: [PATCH 6/8] redone, fixed flake8, validation script --- pandas/core/arrays/datetimes.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 44cc903f77486..2abb872dfd350 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1007,11 +1007,7 @@ def date(self): 'dim', "The number of days in the month") daysinmonth = days_in_month - is_month_start = _field_accessor( - 'is_month_start', - 'is_month_start', - "Logical indicating if first day of month (defined by frequency)") - """ + _is_month_start_doc = """ Indicates whether the date is the first day of the month. Returns @@ -1039,6 +1035,11 @@ def date(self): 2 True dtype: bool """ + is_month_start = _field_accessor( + 'is_month_start', + 'is_month_start', + _is_month_start_doc) + is_month_end = _field_accessor( 'is_month_end', 'is_month_end', From 781a3b92c4181ecd4aa0f755ff50657763fd74cc Mon Sep 17 00:00:00 2001 From: "karmanya.aggarwal" Date: Sat, 20 Oct 2018 11:36:58 +0530 Subject: [PATCH 7/8] merged is_month_start and is_month_end docstrings --- pandas/core/arrays/datetimes.py | 79 +++++++++++++-------------------- 1 file changed, 32 insertions(+), 47 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 84038bebbcb1e..03811891ad381 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -998,77 +998,62 @@ def date(self): 'dim', "The number of days in the month") daysinmonth = days_in_month - _is_month_start_doc = """ - Indicates whether the date is the first day of the month. + _is_month_doc = """ + Indicates whether the date is the {first_or_last} day of the month. Returns ------- - Series of bool - Series of boolean values indicating whether the date is the first - day of the month. + Series or array + For Series, returns a Series with bool. + For DatetimeIndex, returns a bool array. See Also -------- - is_month_end : Return a boolean indicating whether the date is - the last day of the month. + is_month_{end_or_start} : Return a boolean indicating whether the date + is the {last_or_first} day of the month. Examples -------- + This method is available on Series with datetime values under + the ``.dt`` accessor, and directly on DatetimeIndex. + >>> s = pd.Series(pd.date_range("2018-02-27", periods=3)) >>> s 0 2018-02-27 1 2018-02-28 2 2018-03-01 dtype: datetime64[ns] - >>> s.dt.is_month_start - 0 False - 1 False - 2 True + >>> s.dt.is_month_{start_or_end} + 0 {FT[0]} + 1 {FT[1]} + 2 {FT[2]} dtype: bool + + >>> idx = pd.date_range("2018-02-27", periods=3) + >>> idx.is_month_{start_or_end} + array([{FT[3]}, {FT[4]}, {FT[5]}]) """ is_month_start = _field_accessor( 'is_month_start', 'is_month_start', - _is_month_start_doc) + _is_month_doc.format( + first_or_last='first', + start_or_end='start', + FT=[False, False, True, False, False, True], + end_or_start='end', + last_or_first='last' + )) is_month_end = _field_accessor( 'is_month_end', 'is_month_end', - """ - Indicator for whether the date is the last day of the month. - - Returns - ------- - Series or array - For Series, returns a Series with boolean values. For - DatetimeIndex, returns a boolean array. - - See Also - -------- - is_month_start : Indicator for whether the date is the first day - of the month. - - Examples - -------- - This method is available on Series with datetime values under - the ``.dt`` accessor, and directly on DatetimeIndex. - - >>> dates = pd.Series(pd.date_range("2018-02-27", periods=3)) - >>> dates - 0 2018-02-27 - 1 2018-02-28 - 2 2018-03-01 - dtype: datetime64[ns] - >>> dates.dt.is_month_end - 0 False - 1 True - 2 False - dtype: bool - - >>> idx = pd.date_range("2018-02-27", periods=3) - >>> idx.is_month_end - array([False, True, False], dtype=bool) - """) + _is_month_doc.format( + first_or_last='last', + start_or_end='end', + FT=[False, True, False, False, True, False], + end_or_start='start', + last_or_first='first' + )) is_quarter_start = _field_accessor( 'is_quarter_start', 'is_quarter_start', From 9e0f2425daf34c17f9d777e34ce4bd1e5fc0f70b Mon Sep 17 00:00:00 2001 From: "karmanya.aggarwal" Date: Fri, 26 Oct 2018 06:47:48 +0530 Subject: [PATCH 8/8] pandas/core/arrays/datetimes.py simplified --- pandas/core/arrays/datetimes.py | 46 ++++++++++++++++----------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 03811891ad381..b16a399c0bbb1 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1004,13 +1004,15 @@ def date(self): Returns ------- Series or array - For Series, returns a Series with bool. - For DatetimeIndex, returns a bool array. + For Series, returns a Series with boolean values. + For DatetimeIndex, returns a boolean array. See Also -------- - is_month_{end_or_start} : Return a boolean indicating whether the date - is the {last_or_first} day of the month. + is_month_start : Return a boolean indicating whether the date + is the first day of the month. + is_month_end : Return a boolean indicating whether the date + is the last day of the month. Examples -------- @@ -1023,37 +1025,33 @@ def date(self): 1 2018-02-28 2 2018-03-01 dtype: datetime64[ns] - >>> s.dt.is_month_{start_or_end} - 0 {FT[0]} - 1 {FT[1]} - 2 {FT[2]} + >>> s.dt.is_month_start + 0 False + 1 False + 2 True + dtype: bool + >>> s.dt.is_month_end + 0 False + 1 True + 2 False dtype: bool >>> idx = pd.date_range("2018-02-27", periods=3) - >>> idx.is_month_{start_or_end} - array([{FT[3]}, {FT[4]}, {FT[5]}]) + >>> idx.is_month_start + array([False, False, True]) + >>> idx.is_month_end + array([False, True, False]) """ is_month_start = _field_accessor( 'is_month_start', 'is_month_start', - _is_month_doc.format( - first_or_last='first', - start_or_end='start', - FT=[False, False, True, False, False, True], - end_or_start='end', - last_or_first='last' - )) + _is_month_doc.format(first_or_last='first')) is_month_end = _field_accessor( 'is_month_end', 'is_month_end', - _is_month_doc.format( - first_or_last='last', - start_or_end='end', - FT=[False, True, False, False, True, False], - end_or_start='start', - last_or_first='first' - )) + _is_month_doc.format(first_or_last='last')) + is_quarter_start = _field_accessor( 'is_quarter_start', 'is_quarter_start',