Skip to content

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

Closed
wants to merge 0 commits into from

Conversation

howsiwei
Copy link
Contributor

@pep8speaks
Copy link

pep8speaks commented May 15, 2019

Hello @howsiwei! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-05-25 08:22:02 UTC

@codecov
Copy link

codecov bot commented May 15, 2019

Codecov Report

Merging #26400 into master will decrease coverage by 50.5%.
The diff coverage is 25.24%.

Impacted file tree graph

@@             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
Flag Coverage Δ
#multiple ?
#single 41.18% <25.24%> (-0.15%) ⬇️
Impacted Files Coverage Δ
pandas/tseries/offsets.py 45.64% <25.24%> (-51.05%) ⬇️
pandas/io/formats/latex.py 0% <0%> (-100%) ⬇️
pandas/io/sas/sas_constants.py 0% <0%> (-100%) ⬇️
pandas/core/groupby/categorical.py 0% <0%> (-100%) ⬇️
pandas/tseries/plotting.py 0% <0%> (-100%) ⬇️
pandas/tseries/converter.py 0% <0%> (-100%) ⬇️
pandas/io/formats/html.py 0% <0%> (-99.37%) ⬇️
pandas/io/sas/sas7bdat.py 0% <0%> (-91.16%) ⬇️
pandas/io/sas/sas_xport.py 0% <0%> (-90.1%) ⬇️
pandas/core/tools/numeric.py 10.44% <0%> (-89.56%) ⬇️
... and 130 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3b24fb6...394bf0e. Read the comment docs.

@codecov
Copy link

codecov bot commented May 15, 2019

Codecov Report

Merging #26400 into master will increase coverage by <.01%.
The diff coverage is 98.98%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 90.26% <98.98%> (ø) ⬆️
#single 41.74% <33.33%> (-0.04%) ⬇️
Impacted Files Coverage Δ
pandas/tseries/offsets.py 96.79% <98.98%> (+0.1%) ⬆️
pandas/io/gbq.py 78.94% <0%> (-10.53%) ⬇️
pandas/core/frame.py 97.02% <0%> (-0.12%) ⬇️
pandas/util/testing.py 90.7% <0%> (+0.1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44d5498...68fc283. Read the comment docs.

@howsiwei howsiwei force-pushed the master branch 2 times, most recently from 7bfa8a6 to 12894ec Compare May 15, 2019 06:35
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'])
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

for st in self.start:
if other.time() <= st:
return datetime(other.year, other.month, other.day,
st.hour, st.minute)
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comments added

@gfyoung gfyoung requested a review from jreback May 18, 2019 00:47
if _iterable_not_string(start):
start = np.asarray(start)
if len(start) == 0:
raise ValueError('number of starting time cannot be 0')
Copy link
Member

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

if _iterable_not_string(end):
end = np.asarray(end)
if len(end) == 0:
raise ValueError('number of ending time cannot be 0')
Copy link
Member

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

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)')
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated


def _next_opening_time(self, other):
def _next_opening_time(self, other, dir=1):
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 use a different variable besides dir? (It's a python keyword)

Copy link
Contributor Author

@howsiwei howsiwei May 20, 2019

Choose a reason for hiding this comment

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

Changed dir to sign

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")
Copy link
Member

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?

Copy link
Contributor Author

@howsiwei howsiwei May 20, 2019

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.

Copy link
Member

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.

Copy link
Contributor Author

@howsiwei howsiwei May 21, 2019

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

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 so should this be tested? If yes, do we just run _get_closing_time directly in the test function?

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

@howsiwei
Copy link
Contributor Author

howsiwei commented Jun 3, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: BusinessHour to support multiple opening and closing times per day
4 participants