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
Periods exclusion and merging #48
Periods exclusion and merging #48
Conversation
Thanks for taking the time to make this PR :-) However, I have some issues with it:
Also, regarding your tests:
|
Thanks for the feedback! I agree with me not being very clear, I should've provided some docs in this commit too. I do have some questions regarding your issues:
I do think merge perhaps isn't a good name in the first place. I agree that one would assume it somehow merges 2 instances, but rather it removes the redundancies from a list of periods. Do you perhaps know a better name? Could you give some more concrete examples of how you would want to see it being implemented? |
Regarding the >>> Period(monday, thursday).merge(Period(tuesday, friday))
# Period(monday, friday) With this, you don't need the (Period(monday, thursday)
.merge(Period(tuesday, friday))
.exclude(Period(tuesday, thursday))) |
What would happen if you did the following? >>> Period(monday, tuesday).merge(Period(thursday, friday)) Would it just return the original one because they don't overlap? I'll give it a shot the coming days. |
Yeah. I don't know for this specific case. Anyway, I will hold off on that. Adding |
I don't think we should hold off. The PR currently has the features I need and I would definitely want to be able to do that. The merge function can be very useful for opening hours for example, which is what I use it for primarily. Perhaps a better name for the merge function could be union or unite. It could either be classmethod and accept a list of Periods or an instance method that would add it to the given list and unite it after. What are your opinions? |
I understand that it is useful for you but I don't want to bloat the API right now. I want pendulum to stay simple. That's why I see the value of adding If you want these features, you can always make a separate package that include them. |
I get that you don't want to bloat the library and I love the library for it. But I do feel that there is a benefit to having options like these, even though I agree these can be implemented differently/better. There are simply no libraries out there that can manage lists of Periods for opening hours for example. It's unfortunate and I hoped pendulum would be open for a change like that. Thanks for the feedback. For now I'll just try to keep my fork up to date with the changes happening here, but keep these features in. Maybe in the future I'll publish it as a library when I have some more time. |
Know that it's not a definitive no, it's just that do not feel like integrating it in the library for now. I want to focus on stabilizing it and adding features that will make it attractible for new users. I really appreciate the time you took in putting this PR together, I really do. And I hope it won't discourage you from proposing more of them. |
No worries. Maybe even after using my own fork, I'll improve it by using it. The fork is always there in case people need it. |
See #46. This pull request is still being worked on. I have so far added
Period.exclude_from
andPeriod.merge
.Period.exclude_from
: Excludes the Period instance from the given list of Period instances.Period.merge
: Adds the instance period to a list of Period instances and removes overlaps from the list.Period.exclude
will be added in the future. I had accidentally worked onexclude_from
(wanting to implement it the other way around but my brain got confused in the process) and then decidedexclude_from
andexclude
could both be added perhaps.Period._exclude
does all of the dirty work regarding exclusion.Periods are now also sorted first based on their start attribute and then on their end attribute. This is all up for discussion, so please leave some feedback.