From c9282d7b41dc96eb63361bcf6293a6ba5d3ccd89 Mon Sep 17 00:00:00 2001 From: HimanshuAwasthi95 Date: Tue, 20 Mar 2018 00:13:33 +0530 Subject: [PATCH 1/3] DOC : update docstring --- pandas/_libs/tslibs/period.pyx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 008747c0a9e78..7bda2128bd336 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1416,6 +1416,32 @@ cdef class _Period(object): @property def weekday(self): + """ + Get day of the week that a Period falls on. + + Returns + ------- + int + + See Also + -------- + Period.dayofweek : Get the day component of the Period. + Period.week : Get the week of the year on the given Period. + + Examples + -------- + >>> p = pd.Period("2018-03-11", "H") + >>> p.weekday + 6 + + >>> p = pd.Period("2018-02-01", "D") + >>> p.weekday + 3 + + >>> p = pd.Period("2018-01-06", "D") + >>> p.weekday + 5 + """ return self.dayofweek @property From 82084bf51ae4d6f49528d5904092d474ea9a9047 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Mon, 9 Jul 2018 17:57:17 -0500 Subject: [PATCH 2/3] Being more specific on what dayofweek returns for periods --- pandas/_libs/tslibs/period.pyx | 95 +++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 29 deletions(-) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index a395a0b10e360..4817cbe50887a 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -56,7 +56,6 @@ from offsets import _Tick cdef bint PY2 = str == bytes - cdef extern from "period_helper.h": int FR_ANN int FR_QTR @@ -1384,34 +1383,49 @@ cdef class _Period(object): @property def dayofweek(self): """ - Return the day of the week. + Day of the week the period lies in, with Monday=0 and Sunday=6. + + If the period frequency is lower than daily (e.g. hourly), and the + period spans over multiple days, the day at the start of the period is + used. - This attribute returns the day of the week on which the particular - date for the given period occurs depending on the frequency with - Monday=0, Sunday=6. + If the frequency is higher than daily (e.g. monthly), the last day + of the period is used. Returns ------- - Int - Range from 0 to 6 (included). + int + Day of the week. - See also + See Also -------- - Period.dayofyear : Return the day of the year. - Period.daysinmonth : Return the number of days in that month. + Period.dayofweek : Day of the week the period lies in. + Period.weekday : Alias of Period.dayofweek. + Period.day : Day of the month. + Period.dayofyear : Day of the year. Examples -------- - >>> period1 = pd.Period('2012-1-1 19:00', freq='H') - >>> period1 - Period('2012-01-01 19:00', 'H') - >>> period1.dayofweek + >>> per = pd.Period('2017-12-31 22:00', 'H') + >>> per.dayofweek 6 - >>> period2 = pd.Period('2013-1-9 11:00', freq='H') - >>> period2 - Period('2013-01-09 11:00', 'H') - >>> period2.dayofweek + For periods that span over multiple days, the day at the beginning of + the period is returned. + + >>> per = pd.Period('2017-12-31 22:00', '4H') + >>> per.dayofweek + 6 + >>> per.start_time.dayofweek + 6 + + For periods with a frequancy higher than days, the last day of the + period is returned. + + >>> per = pd.Period('2018-01', 'M') + >>> per.dayofweek + 2 + >>> per.end_time.dayofweek 2 """ base, mult = get_freq_code(self.freq) @@ -1420,31 +1434,54 @@ cdef class _Period(object): @property def weekday(self): """ - Get day of the week that a Period falls on. + Day of the week the period lies in, with Monday=0 and Sunday=6. + + If the period frequency is lower than daily (e.g. hourly), and the + period spans over multiple days, the day at the start of the period is + used. + + If the frequency is higher than daily (e.g. monthly), the last day + of the period is used. Returns ------- int + Day of the week. See Also -------- - Period.dayofweek : Get the day component of the Period. - Period.week : Get the week of the year on the given Period. + Period.dayofweek : Day of the week the period lies in. + Period.weekday : Alias of Period.dayofweek. + Period.day : Day of the month. + Period.dayofyear : Day of the year. Examples -------- - >>> p = pd.Period("2018-03-11", "H") - >>> p.weekday + >>> per = pd.Period('2017-12-31 22:00', 'H') + >>> per.dayofweek 6 - >>> p = pd.Period("2018-02-01", "D") - >>> p.weekday - 3 + For periods that span over multiple days, the day at the beginning of + the period is returned. - >>> p = pd.Period("2018-01-06", "D") - >>> p.weekday - 5 + >>> per = pd.Period('2017-12-31 22:00', '4H') + >>> per.dayofweek + 6 + >>> per.start_time.dayofweek + 6 + + For periods with a frequancy higher than days, the last day of the + period is returned. + + >>> per = pd.Period('2018-01', 'M') + >>> per.dayofweek + 2 + >>> per.end_time.dayofweek + 2 """ + # Docstring is a duplicate from dayofweek. Reusing docstrings with + # Appender doesn't work for properties in Cython files, and setting + # the __doc__ attribute is also not possible. return self.dayofweek @property From fcaaf4b114918a9cb1c5dbd0e77b06a9902838e2 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Tue, 17 Jul 2018 21:54:18 +0100 Subject: [PATCH 3/3] Fixed typo in docstring --- pandas/_libs/tslibs/period.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index dc3d66b8a01f3..59db371833957 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1415,7 +1415,7 @@ cdef class _Period(object): >>> per.start_time.dayofweek 6 - For periods with a frequancy higher than days, the last day of the + For periods with a frequency higher than days, the last day of the period is returned. >>> per = pd.Period('2018-01', 'M') @@ -1466,7 +1466,7 @@ cdef class _Period(object): >>> per.start_time.dayofweek 6 - For periods with a frequancy higher than days, the last day of the + For periods with a frequency higher than days, the last day of the period is returned. >>> per = pd.Period('2018-01', 'M')