Skip to content

DOC: Update start/end parameter for BusinessHour and CustomBusinessHour #49774

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 2 commits into from
Dec 6, 2022

Conversation

gandhis1
Copy link
Contributor

These are all valid usages. Examples from pandas-stubs here:

https://github.com/pandas-dev/pandas-stubs/blob/main/tests/test_timefuncs.py#L601-L639

@@ -1613,9 +1613,9 @@ cdef class BusinessHour(BusinessMixin):
Normalize start/end dates to midnight before generating date range.
weekmask : str, Default 'Mon Tue Wed Thu Fri'
Weekmask of valid business days, passed to ``numpy.busdaycalendar``.
start : str, default "09:00"
start : str, time, or list of str/time, default "09:00"
Copy link
Member

Choose a reason for hiding this comment

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

Could you add to the Examples section showing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mroeschke Done

@mroeschke mroeschke added Docs Frequency DateOffsets labels Nov 18, 2022
@gandhis1 gandhis1 force-pushed the time branch 3 times, most recently from 22c69cf to 4c0ffb9 Compare December 4, 2022 04:49
>>> ts + pd.offsets.CustomBusinessHour(end=dt_time(19, 0))
Timestamp('2022-08-05 17:00:00')
>>> ts + pd.offsets.CustomBusinessHour(start=[dt_time(9, 0), "20:00"],
... end=["17:00", dt_time(22, 0)])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The docstrings examples apparently get compiled. This is failing. I tried time, but the error seemed to indicate it uses the same imports as the module itself - so I updated to using dt_time, which still didn't work. Based on the following import:

from cpython.datetime cimport (
    PyDate_Check,
    PyDateTime_Check,
    PyDelta_Check,
    date,
    datetime,
    import_datetime,
    time as dt_time,
    timedelta,
)

I would have expected dt_time to work. What's the right syntax here?

End time of your custom business hour in 24h format.

Examples
--------
>>> ts = pd.Timestamp(2022, 8, 5, 16)
>>> ts + pd.offsets.BusinessHour()
Timestamp('2022-08-08 09:00:00')
>>> ts + pd.offsets.BusinessHour(start="11:00")
Timestamp('2022-08-08 11:00:00')
>>> ts + pd.offsets.BusinessHour(end=dt_time(19, 0))
Copy link
Member

Choose a reason for hiding this comment

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

You'll need to import dt_time before the first usage.

>>> from datetime import time as dt_time

…usinessHour to mention allowed input types of time and list of str/time
…Hour

This covers usage of datetime.time start/end values as well as multiple start and end values
@mroeschke mroeschke added this to the 2.0 milestone Dec 6, 2022
@mroeschke mroeschke merged commit 1b23a7d into pandas-dev:main Dec 6, 2022
@mroeschke
Copy link
Member

Thanks @gandhis1

@gandhis1 gandhis1 deleted the time branch December 6, 2022 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants