API Reference#

This page contains auto-generated API reference documentation for the EpiWeeks package.

class Week(year, week, system='cdc', validate=True)[source]#

Bases: object

A Week object represents a week in epidemiological week calendar.

Parameters:
  • year (int) – Epidemiological year.

  • week (int) – Epidemiological week.

  • system (str) – Week numbering system, which may be cdc where the week starts on Sunday or iso where the week starts on Monday.

  • validate (bool) – Whether to validate year, week and system or not.

Raises:
  • ValueError – When year is out of supported range.

  • ValueError – When week is out of weeks range for year.

  • ValueError – When system is not within supported systems.

classmethod fromdate(date_object, system='cdc')[source]#

Construct Week object from a date.

Parameters:
  • date_object (date) – Python date object.

  • system (str) – Week numbering system, which may be cdc where the week starts on Sunday or iso where the week starts on Monday.

Return type:

Week

classmethod fromstring(week_string, system='cdc', validate=True)[source]#

Construct Week object from a formatted string.

Parameters:
  • week_string (str) – Week string formatted as YYYYww, YYYYWww, or YYYY-Www. If the string ends with weekday as in ISO formats, weekday will be ignored.

  • system (str) – Week numbering system, which may be cdc where the week starts on Sunday or iso where the week starts on Monday.

  • validate (bool) – Whether to validate year, week and system or not.

Return type:

Week

classmethod thisweek(system='cdc')[source]#

Construct Week object from current date.

Parameters:

system (str) – Week numbering system, which may be cdc where the week starts on Sunday or iso where the week starts on Monday.

Return type:

Week

property year: int#

Return year as an integer

property week: int#

Return week number as an integer

property system: str#

Return week numbering system as a string

weektuple()[source]#

Return week as a tuple of (year, week).

Return type:

Tuple[int, int]

cdcformat()[source]#

Return a string representing the week in CDC format YYYYww.

Return type:

str

isoformat()[source]#

Return a string representing the week in ISO compact format YYYYWww.

Return type:

str

startdate()[source]#

Return date for first day of week.

Return type:

date

enddate()[source]#

Return date for last day of week.

Return type:

date

iterdates()[source]#

Return an iterator that yield date objects for all days of week.

Return type:

Iterator[date]

daydate(weekday=6)[source]#

Return date for specific weekday of week.

Parameters:

weekday (int) – Week day, which may be 0..6 where Monday is 0 and Sunday is 6.

Return type:

date

class Year(year, system='cdc')[source]#

Bases: object

A Year object represents a year in epidemiological week calendar.

Parameters:
  • year (int) – Epidemiological year.

  • system (str) – Week numbering system, which may be cdc where the week starts on Sunday or iso where the week starts on Monday.

Raises:
  • ValueError – When year is out of supported range.

  • ValueError – When system is not within supported systems.

classmethod thisyear(system='cdc')[source]#

Construct Year object from current date.

Parameters:

system (str) – Week numbering system, which may be cdc where the week starts on Sunday or iso where the week starts on Monday.

Return type:

Year

property year: int#

Return year as an integer

property system: str#

Return week numbering system as a string

totalweeks()[source]#

Return number of weeks in year.

Return type:

int

startdate()[source]#

Return date for first day of first week of year.

Return type:

date

enddate()[source]#

Return date for last day of last week of year.

Return type:

date

iterweeks()[source]#

Return an iterator that yield Week objects for all weeks of year.

Return type:

Iterator[Week]