From f8c5d5debb56e09b72242617c3c7ae7a346a2baf Mon Sep 17 00:00:00 2001 From: akshay-babbar Date: Fri, 13 Jan 2023 20:23:49 +0530 Subject: [PATCH 01/12] Enhanced the documentation and added examples in ts offsets Week class --- pandas/_libs/tslibs/offsets.pyx | 35 +++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 48104965ec42b..862edd736556f 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2490,13 +2490,36 @@ cdef class SemiMonthBegin(SemiMonthOffset): cdef class Week(SingleConstructorOffset): """ - Weekly offset. + Weekly offset. - Parameters - ---------- - weekday : int or None, default None - Always generate specific day of week. 0 for Monday. - """ + Parameters + ---------- + weekday : int or None, default None + Always generate specific day of week. 0 for Monday and 6 for Sunday. + + Examples + --------- + ## Below examples explain the usage of this object. + ## Importing modules + import pandas as pd + + date_format = "%Y-%m-%d" + date_object = pd.to_datetime("2023-01-13",format = date_format) + print(date_object) + ## 2023-01-13 00:00:00 + + date_plus_one_week = date_object + pd.tseries.offsets.Week(1) + print(date_plus_one_week) + #2023-01-20 00:00:00 + + date_next_Monday = date_object + pd.tseries.offsets.Week(weekday=0) + print(date_next_Monday) + #2023-01-16 00:00:00 + + date_next_Sunday = date_object + pd.tseries.offsets.Week(weekday=6) + print(date_next_Sunday) + #2023-01-15 00:00:00 + """ _inc = timedelta(weeks=1) _prefix = "W" From 6c8648bc90bfded0cb1046f7832d6771be9b154c Mon Sep 17 00:00:00 2001 From: akshay-babbar Date: Fri, 13 Jan 2023 20:59:23 +0530 Subject: [PATCH 02/12] Fixed indentation and examples in docs --- pandas/_libs/tslibs/offsets.pyx | 57 ++++++++++++++++----------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 862edd736556f..5bff48cfe1b7b 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2490,36 +2490,35 @@ cdef class SemiMonthBegin(SemiMonthOffset): cdef class Week(SingleConstructorOffset): """ - Weekly offset. - Parameters - ---------- - weekday : int or None, default None - Always generate specific day of week. 0 for Monday and 6 for Sunday. - - Examples - --------- - ## Below examples explain the usage of this object. - ## Importing modules - import pandas as pd - - date_format = "%Y-%m-%d" - date_object = pd.to_datetime("2023-01-13",format = date_format) - print(date_object) - ## 2023-01-13 00:00:00 - - date_plus_one_week = date_object + pd.tseries.offsets.Week(1) - print(date_plus_one_week) - #2023-01-20 00:00:00 - - date_next_Monday = date_object + pd.tseries.offsets.Week(weekday=0) - print(date_next_Monday) - #2023-01-16 00:00:00 - - date_next_Sunday = date_object + pd.tseries.offsets.Week(weekday=6) - print(date_next_Sunday) - #2023-01-15 00:00:00 - """ + Weekly offset. + + Parameters + ---------- + weekday : int or None, default None + Always generate specific day of week. 0 for Monday and 6 for Sunday. + + Examples + --------- + import pandas as pd + + >>> date_format = "%Y-%m-%d" + >>> date_object = pd.to_datetime("2023-01-13",format = date_format) + >>> print(date_object) + 2023-01-13 00:00:00 + + >>> date_plus_one_week = date_object + pd.tseries.offsets.Week(n=1) + >>> print(date_plus_one_week) + 2023-01-20 00:00:00 + + >>> date_next_Monday = date_object + pd.tseries.offsets.Week(weekday=0) + >>> print(date_next_Monday) + 2023-01-16 00:00:00 + + >>> date_next_Sunday = date_object + pd.tseries.offsets.Week(weekday=6) + >>> print(date_next_Sunday) + 2023-01-15 00:00:00 + """ _inc = timedelta(weeks=1) _prefix = "W" From 4f23831ff7c9413e2596f778d99cf6811232ee85 Mon Sep 17 00:00:00 2001 From: akshay-babbar Date: Fri, 13 Jan 2023 21:04:22 +0530 Subject: [PATCH 03/12] Removed pd import from docs --- pandas/_libs/tslibs/offsets.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 5bff48cfe1b7b..a098485b1aa32 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2500,7 +2500,6 @@ cdef class Week(SingleConstructorOffset): Examples --------- - import pandas as pd >>> date_format = "%Y-%m-%d" >>> date_object = pd.to_datetime("2023-01-13",format = date_format) From b1c61103b77d8eab1905d7db0bab238406e678a6 Mon Sep 17 00:00:00 2001 From: akshay-babbar Date: Fri, 13 Jan 2023 21:38:18 +0530 Subject: [PATCH 04/12] Remove extra line breaks in doc strings --- pandas/_libs/tslibs/offsets.pyx | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index a098485b1aa32..cd29b55b3387c 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2490,9 +2490,7 @@ cdef class SemiMonthBegin(SemiMonthOffset): cdef class Week(SingleConstructorOffset): """ - Weekly offset. - Parameters ---------- weekday : int or None, default None @@ -2500,7 +2498,6 @@ cdef class Week(SingleConstructorOffset): Examples --------- - >>> date_format = "%Y-%m-%d" >>> date_object = pd.to_datetime("2023-01-13",format = date_format) >>> print(date_object) From de464ecb498400241f85d2ace6f1615d303b49dc Mon Sep 17 00:00:00 2001 From: akshay-babbar Date: Fri, 13 Jan 2023 21:43:09 +0530 Subject: [PATCH 05/12] Remove extra line breaks in doc strings-v1 --- pandas/_libs/tslibs/offsets.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index cd29b55b3387c..498a14f6c176d 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2491,11 +2491,11 @@ cdef class SemiMonthBegin(SemiMonthOffset): cdef class Week(SingleConstructorOffset): """ Weekly offset. + Parameters ---------- weekday : int or None, default None Always generate specific day of week. 0 for Monday and 6 for Sunday. - Examples --------- >>> date_format = "%Y-%m-%d" From 9a493e9ddc1bdcc5bde4c1efa334f3cb39ee53fe Mon Sep 17 00:00:00 2001 From: akshay-babbar Date: Fri, 13 Jan 2023 21:46:56 +0530 Subject: [PATCH 06/12] Remove extra line breaks in doc strings-v2 --- pandas/_libs/tslibs/offsets.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 498a14f6c176d..2d8eb4ad30b71 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2496,6 +2496,7 @@ cdef class Week(SingleConstructorOffset): ---------- weekday : int or None, default None Always generate specific day of week. 0 for Monday and 6 for Sunday. + Examples --------- >>> date_format = "%Y-%m-%d" From 7e3afa3f19ac95b608c8cbdbd905d3fea780af35 Mon Sep 17 00:00:00 2001 From: akshay-babbar Date: Fri, 13 Jan 2023 21:54:47 +0530 Subject: [PATCH 07/12] Added extended summary and see also section --- pandas/_libs/tslibs/offsets.pyx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 2d8eb4ad30b71..0f58a38e6c888 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2492,11 +2492,17 @@ cdef class Week(SingleConstructorOffset): """ Weekly offset. + This can increment the date object by given week or weekdays. + Parameters ---------- weekday : int or None, default None Always generate specific day of week. 0 for Monday and 6 for Sunday. + See Also + -------- + pd.tseries.offsets.WeekOfMonth : Describes monthly dates like "the Tuesday of the 2nd week of each month". + Examples --------- >>> date_format = "%Y-%m-%d" From e99a1ec858bd1e3e82f0d10487ab056f444351de Mon Sep 17 00:00:00 2001 From: akshay-babbar Date: Fri, 13 Jan 2023 21:59:35 +0530 Subject: [PATCH 08/12] Added extended summary and see also section-v1 --- pandas/_libs/tslibs/offsets.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 0f58a38e6c888..f00339a6ec819 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2493,7 +2493,6 @@ cdef class Week(SingleConstructorOffset): Weekly offset. This can increment the date object by given week or weekdays. - Parameters ---------- weekday : int or None, default None From f68b9f8ae400c3b0abc3c885ca38b66b889138f8 Mon Sep 17 00:00:00 2001 From: akshay-babbar Date: Fri, 13 Jan 2023 22:31:42 +0530 Subject: [PATCH 09/12] Removed extender summary, small cased var names and used pd.Timestamp --- pandas/_libs/tslibs/offsets.pyx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index caa8f01b3aac8..facd19b61ec77 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2778,8 +2778,6 @@ cdef class SemiMonthBegin(SemiMonthOffset): cdef class Week(SingleConstructorOffset): """ Weekly offset. - - This can increment the date object by given week or weekdays. Parameters ---------- weekday : int or None, default None @@ -2791,21 +2789,21 @@ cdef class Week(SingleConstructorOffset): Examples --------- - >>> date_format = "%Y-%m-%d" - >>> date_object = pd.to_datetime("2023-01-13",format = date_format) - >>> print(date_object) + + >>> date_object = pd.Timestamp("2023-01-13") + >>> date_object 2023-01-13 00:00:00 >>> date_plus_one_week = date_object + pd.tseries.offsets.Week(n=1) - >>> print(date_plus_one_week) + >>> date_plus_one_week 2023-01-20 00:00:00 - >>> date_next_Monday = date_object + pd.tseries.offsets.Week(weekday=0) - >>> print(date_next_Monday) + >>> date_next_monday = date_object + pd.tseries.offsets.Week(weekday=0) + >>> date_next_monday 2023-01-16 00:00:00 - >>> date_next_Sunday = date_object + pd.tseries.offsets.Week(weekday=6) - >>> print(date_next_Sunday) + >>> date_next_sunday = date_object + pd.tseries.offsets.Week(weekday=6) + >>> date_next_sunday 2023-01-15 00:00:00 """ From 02f7fda469a94b87fd2c09d35371b70966f90953 Mon Sep 17 00:00:00 2001 From: akshay-babbar Date: Fri, 13 Jan 2023 22:43:45 +0530 Subject: [PATCH 10/12] Added line space --- pandas/_libs/tslibs/offsets.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index facd19b61ec77..a9421dd5a9917 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2778,6 +2778,7 @@ cdef class SemiMonthBegin(SemiMonthOffset): cdef class Week(SingleConstructorOffset): """ Weekly offset. + Parameters ---------- weekday : int or None, default None From e7282a7fac24c62effa750139da2c256db1687a3 Mon Sep 17 00:00:00 2001 From: akshay-babbar Date: Mon, 16 Jan 2023 21:12:29 +0530 Subject: [PATCH 11/12] Fixed long lines and some print statements --- pandas/_libs/tslibs/offsets.pyx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index a9421dd5a9917..f9ccfb68d66c6 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2786,26 +2786,27 @@ cdef class Week(SingleConstructorOffset): See Also -------- - pd.tseries.offsets.WeekOfMonth : Describes monthly dates like "the Tuesday of the 2nd week of each month". + pd.tseries.offsets.WeekOfMonth : Describes monthly dates like + "the Tuesday of the 2nd week of each month". Examples --------- >>> date_object = pd.Timestamp("2023-01-13") >>> date_object - 2023-01-13 00:00:00 + Timestamp('2023-01-13 00:00:00') >>> date_plus_one_week = date_object + pd.tseries.offsets.Week(n=1) >>> date_plus_one_week - 2023-01-20 00:00:00 + Timestamp('2023-01-20 00:00:00') >>> date_next_monday = date_object + pd.tseries.offsets.Week(weekday=0) >>> date_next_monday - 2023-01-16 00:00:00 + Timestamp('2023-01-16 00:00:00') >>> date_next_sunday = date_object + pd.tseries.offsets.Week(weekday=6) >>> date_next_sunday - 2023-01-15 00:00:00 + Timestamp('2023-01-15 00:00:00') """ _inc = timedelta(weeks=1) From 17d8965e46d05799e6570f57f3ee676d7439b589 Mon Sep 17 00:00:00 2001 From: akshay-babbar Date: Mon, 16 Jan 2023 21:31:04 +0530 Subject: [PATCH 12/12] Fixed long lines and some print statements-v1 --- pandas/_libs/tslibs/offsets.pyx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index f9ccfb68d66c6..17d4e0dd3234b 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2782,12 +2782,14 @@ cdef class Week(SingleConstructorOffset): Parameters ---------- weekday : int or None, default None - Always generate specific day of week. 0 for Monday and 6 for Sunday. + Always generate specific day of week. + 0 for Monday and 6 for Sunday. See Also -------- - pd.tseries.offsets.WeekOfMonth : Describes monthly dates like - "the Tuesday of the 2nd week of each month". + pd.tseries.offsets.WeekOfMonth : + Describes monthly dates like, the Tuesday of the + 2nd week of each month. Examples ---------