Skip to content

Commit f8b1e5e

Browse files
IHackPyaeltanawy
authored andcommitted
DOC : Update the Period.dayofweek/Period.weekday docstring (pandas-dev#20413)
1 parent a254468 commit f8b1e5e

File tree

1 file changed

+81
-18
lines changed

1 file changed

+81
-18
lines changed

pandas/_libs/tslibs/period.pyx

+81-18
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ from offsets import _Tick
5454

5555
cdef bint PY2 = str == bytes
5656

57-
5857
cdef extern from "period_helper.h":
5958
int FR_ANN
6059
int FR_QTR
@@ -1380,41 +1379,105 @@ cdef class _Period(object):
13801379
@property
13811380
def dayofweek(self):
13821381
"""
1383-
Return the day of the week.
1382+
Day of the week the period lies in, with Monday=0 and Sunday=6.
1383+
1384+
If the period frequency is lower than daily (e.g. hourly), and the
1385+
period spans over multiple days, the day at the start of the period is
1386+
used.
13841387
1385-
This attribute returns the day of the week on which the particular
1386-
date for the given period occurs depending on the frequency with
1387-
Monday=0, Sunday=6.
1388+
If the frequency is higher than daily (e.g. monthly), the last day
1389+
of the period is used.
13881390
13891391
Returns
13901392
-------
1391-
Int
1392-
Range from 0 to 6 (included).
1393+
int
1394+
Day of the week.
13931395
1394-
See also
1396+
See Also
13951397
--------
1396-
Period.dayofyear : Return the day of the year.
1397-
Period.daysinmonth : Return the number of days in that month.
1398+
Period.dayofweek : Day of the week the period lies in.
1399+
Period.weekday : Alias of Period.dayofweek.
1400+
Period.day : Day of the month.
1401+
Period.dayofyear : Day of the year.
13981402
13991403
Examples
14001404
--------
1401-
>>> period1 = pd.Period('2012-1-1 19:00', freq='H')
1402-
>>> period1
1403-
Period('2012-01-01 19:00', 'H')
1404-
>>> period1.dayofweek
1405+
>>> per = pd.Period('2017-12-31 22:00', 'H')
1406+
>>> per.dayofweek
1407+
6
1408+
1409+
For periods that span over multiple days, the day at the beginning of
1410+
the period is returned.
1411+
1412+
>>> per = pd.Period('2017-12-31 22:00', '4H')
1413+
>>> per.dayofweek
1414+
6
1415+
>>> per.start_time.dayofweek
14051416
6
14061417
1407-
>>> period2 = pd.Period('2013-1-9 11:00', freq='H')
1408-
>>> period2
1409-
Period('2013-01-09 11:00', 'H')
1410-
>>> period2.dayofweek
1418+
For periods with a frequency higher than days, the last day of the
1419+
period is returned.
1420+
1421+
>>> per = pd.Period('2018-01', 'M')
1422+
>>> per.dayofweek
1423+
2
1424+
>>> per.end_time.dayofweek
14111425
2
14121426
"""
14131427
base, mult = get_freq_code(self.freq)
14141428
return pweekday(self.ordinal, base)
14151429

14161430
@property
14171431
def weekday(self):
1432+
"""
1433+
Day of the week the period lies in, with Monday=0 and Sunday=6.
1434+
1435+
If the period frequency is lower than daily (e.g. hourly), and the
1436+
period spans over multiple days, the day at the start of the period is
1437+
used.
1438+
1439+
If the frequency is higher than daily (e.g. monthly), the last day
1440+
of the period is used.
1441+
1442+
Returns
1443+
-------
1444+
int
1445+
Day of the week.
1446+
1447+
See Also
1448+
--------
1449+
Period.dayofweek : Day of the week the period lies in.
1450+
Period.weekday : Alias of Period.dayofweek.
1451+
Period.day : Day of the month.
1452+
Period.dayofyear : Day of the year.
1453+
1454+
Examples
1455+
--------
1456+
>>> per = pd.Period('2017-12-31 22:00', 'H')
1457+
>>> per.dayofweek
1458+
6
1459+
1460+
For periods that span over multiple days, the day at the beginning of
1461+
the period is returned.
1462+
1463+
>>> per = pd.Period('2017-12-31 22:00', '4H')
1464+
>>> per.dayofweek
1465+
6
1466+
>>> per.start_time.dayofweek
1467+
6
1468+
1469+
For periods with a frequency higher than days, the last day of the
1470+
period is returned.
1471+
1472+
>>> per = pd.Period('2018-01', 'M')
1473+
>>> per.dayofweek
1474+
2
1475+
>>> per.end_time.dayofweek
1476+
2
1477+
"""
1478+
# Docstring is a duplicate from dayofweek. Reusing docstrings with
1479+
# Appender doesn't work for properties in Cython files, and setting
1480+
# the __doc__ attribute is also not possible.
14181481
return self.dayofweek
14191482

14201483
@property

0 commit comments

Comments
 (0)