Skip to content

DOC: Fixed examples in pandas/tseries #32935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
MSG='Doctests generic.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/generic.py
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests tseries' ; echo $MSG
pytest -q --doctest-modules pandas/tseries/
RET=$(($RET + $?)) ; echo $MSG "DONE"
fi

### DOCSTRINGS ###
Expand Down
10 changes: 5 additions & 5 deletions pandas/tseries/frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ def to_offset(freq) -> Optional[DateOffset]:

Examples
--------
>>> to_offset('5min')
>>> to_offset("5min")
<5 * Minutes>

>>> to_offset('1D1H')
>>> to_offset("1D1H")
<25 * Hours>

>>> to_offset(('W', 2))
>>> to_offset(("W", 2))
<2 * Weeks: weekday=6>

>>> to_offset((2, 'B'))
>>> to_offset((2, "B"))
<2 * BusinessDays>

>>> to_offset(datetime.timedelta(days=1))
>>> to_offset(pd.Timedelta(days=1))
<Day>

>>> to_offset(Hour())
Expand Down
37 changes: 28 additions & 9 deletions pandas/tseries/holiday.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,34 @@ class from pandas.tseries.offsets
--------
>>> from pandas.tseries.holiday import Holiday, nearest_workday
>>> from dateutil.relativedelta import MO
>>> USMemorialDay = Holiday('Memorial Day', month=5, day=31,
offset=pd.DateOffset(weekday=MO(-1)))
>>> USLaborDay = Holiday('Labor Day', month=9, day=1,
offset=pd.DateOffset(weekday=MO(1)))
>>> July3rd = Holiday('July 3rd', month=7, day=3,)
>>> NewYears = Holiday('New Years Day', month=1, day=1,
observance=nearest_workday),
>>> July3rd = Holiday('July 3rd', month=7, day=3,
days_of_week=(0, 1, 2, 3))

>>> USMemorialDay = Holiday(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does a code check complain about this without this change? this makes it harder to copy/paste an example

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, flake8 complains that this line's length is larger than 88 characters.

... "Memorial Day", month=5, day=31, offset=pd.DateOffset(weekday=MO(-1))
... )
>>> USMemorialDay
Holiday: Memorial Day (month=5, day=31, offset=<DateOffset: weekday=MO(-1)>)

>>> USLaborDay = Holiday(
... "Labor Day", month=9, day=1, offset=pd.DateOffset(weekday=MO(1))
... )
>>> USLaborDay
Holiday: Labor Day (month=9, day=1, offset=<DateOffset: weekday=MO(+1)>)

>>> July3rd = Holiday("July 3rd", month=7, day=3)
>>> July3rd
Holiday: July 3rd (month=7, day=3, )

>>> NewYears = Holiday(
... "New Years Day", month=1, day=1, observance=nearest_workday
... )
>>> NewYears # doctest: +SKIP
Holiday: New Years Day (
month=1, day=1, observance=<function nearest_workday at 0x66545e9bc440>
)

>>> July3rd = Holiday("July 3rd", month=7, day=3, days_of_week=(0, 1, 2, 3))
>>> July3rd
Holiday: July 3rd (month=7, day=3, )
"""
if offset is not None and observance is not None:
raise NotImplementedError("Cannot use both offset and observance.")
Expand Down