-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Support multiple opening hours intervals for BusinessHour #26400
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #26400 +/- ##
===========================================
- Coverage 91.69% 41.18% -50.51%
===========================================
Files 174 174
Lines 50743 50792 +49
===========================================
- Hits 46527 20917 -25610
- Misses 4216 29875 +25659
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26400 +/- ##
==========================================
+ Coverage 91.74% 91.75% +<.01%
==========================================
Files 174 174
Lines 50763 50801 +38
==========================================
+ Hits 46575 46610 +35
- Misses 4188 4191 +3
Continue to review full report at Codecov.
|
7bfa8a6
to
12894ec
Compare
with pytest.raises(ValueError): | ||
BusinessHour(start=['09:00', '11:00'], end=['10:00']) | ||
with pytest.raises(ValueError): | ||
BusinessHour(start=['09:00', '11:00'], end=['12:00', '20:00']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the pytest.raises
calls (for this entire test function) to include a check for the error message? Just pass in match
parameter that indicates the expected message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
pandas/tseries/offsets.py
Outdated
for st in self.start: | ||
if other.time() <= st: | ||
return datetime(other.year, other.month, other.day, | ||
st.hour, st.minute) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment your code to explain what all of this logic is for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments added
pandas/tseries/offsets.py
Outdated
if _iterable_not_string(start): | ||
start = np.asarray(start) | ||
if len(start) == 0: | ||
raise ValueError('number of starting time cannot be 0') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Must include at least 1 start time"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
pandas/tseries/offsets.py
Outdated
if _iterable_not_string(end): | ||
end = np.asarray(end) | ||
if len(end) == 0: | ||
raise ValueError('number of ending time cannot be 0') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Must include at least 1 end time"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
pandas/tseries/offsets.py
Outdated
total_secs += self._get_business_hours_by_sec( | ||
end[i], start[(i + 1) % num_openings]) | ||
if total_secs != 24 * 60 * 60: | ||
raise ValueError('invalid starting and ending time(s)') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this error message a little more informative?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
pandas/tseries/offsets.py
Outdated
|
||
def _next_opening_time(self, other): | ||
def _next_opening_time(self, other, dir=1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use a different variable besides dir
? (It's a python keyword)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed dir
to sign
pandas/tseries/offsets.py
Outdated
if st.hour == dt.hour and st.minute == dt.minute: | ||
return dt + timedelta( | ||
seconds=self._get_business_hours_by_sec(st, self.end[i])) | ||
raise ValueError("dt should be a starting time") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test where this is hit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean where ValueError
is raised here? It would never happen if only public methods are called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well can this ValueError
get floated up to the user? If so, we should have a test to catch it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only if user calls _get_closing_time
directly him/herself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mroeschke so should this be tested? If yes, do we just run _get_closing_time
directly in the test function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if this error can never be hit by the user using public methods, I'm still not sure if we entirely need this error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I remove the raise statement? Or add a comment to indicate that it would never be hit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If if st.hour == dt.hour and st.minute == dt.minute:
is always guaranteed to get hit, then you can remove the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed the error and added a comment.
For some reason this PR is automatically closed after rebasing on latest master. I have created a new PR at #26628 and have edited as per all the comments here. |
git diff upstream/master -u -- "*.py" | flake8 --diff