Skip to content

Replaced append(Period) with add_interval(kwargs) #138

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 10 commits into from
Nov 29, 2022

Conversation

BSchilperoort
Copy link
Contributor

@BSchilperoort BSchilperoort commented Nov 18, 2022

This PR will tackle Peter's comments about the Period classes:

  • Perhaps we should hide the Period class from the public API. Why not calendar.add_target_period(...) and add_precursor_period? I found myself doing calendar.append(PrecursorPeriod("1d")), which I think is a sign of suboptimal API
  • Relatedly, should it be add_target, add_target_period, add_target_interval, add_period(target=True), add_interval(target=True), or add_block(target=True)? What's the difference between a precursor and targetperiod?
  • I would love to be able to add a period by specifying a length and end day, e.g. if I want to issue a forecast by the end of may, I want to start appending precursors from 31 may backwards. See Specifying start/end day and length of a target/precursor period lilio#3

Changes:

  • Intervals are appended using calendar.add_interval("target", "10d", gap="2d')
    • TargetPeriod and PrecursorPeriod classes are still used in the backend.
  • Support for non-day lengths and gaps is added, required a rewrite of skip_nyears
    • E.g., calendar.add_interval("target", "2M")
  • Tests and notebook have been updated
  • mypy version is pinned, see Pinning mypy version #134.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@BSchilperoort BSchilperoort marked this pull request as ready for review November 18, 2022 13:19
@BSchilperoort BSchilperoort requested review from Peter9192 and geek-yang and removed request for Peter9192 November 18, 2022 13:20
Copy link
Member

@geek-yang geek-yang left a comment

Choose a reason for hiding this comment

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

Looks really nice to me. I checked the codes and the notebook. The tasks are clearly defined and the implementations are quite clean. Only got one minor comment, which concerns the test. I would wait for the feedback from @Peter9192, before this PR can be merged. Nice work!

Comment on lines +175 to +183
while True:
prev_end_calendar = self._get_anchor(proto_year - 1 - skip_years)
for target in self._targets:
prev_end_calendar += target.gap
prev_end_calendar += target.length
if prev_end_calendar > start_calendar:
skip_years += 1
else:
break
Copy link
Member

Choose a reason for hiding this comment

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

Very smart design 😎 🆒.

interval("2020-12-01", "2021-01-01", closed="left")]
)
assert np.array_equal(cal.flat, expected)

Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to have one more test for the allow_overlap case.

@Peter9192
Copy link
Contributor

Peter9192 commented Nov 25, 2022

closes #134 ?

@Peter9192
Copy link
Contributor

  • Intervals are appended using calendar.append("target", "10d", gap="2d')

calendar.add_interval, right?

Copy link
Contributor

@Peter9192 Peter9192 left a comment

Choose a reason for hiding this comment

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

Nice!

@BSchilperoort BSchilperoort linked an issue Nov 29, 2022 that may be closed by this pull request
@BSchilperoort
Copy link
Contributor Author

  • Intervals are appended using calendar.append("target", "10d", gap="2d')

calendar.add_interval, right?

Yes! I mistyped that.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

95.0% 95.0% Coverage
0.0% 0.0% Duplication

@BSchilperoort BSchilperoort merged commit af7f607 into calendar_development Nov 29, 2022
@BSchilperoort BSchilperoort deleted the refactor_period_appending branch November 29, 2022 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pinning mypy version
3 participants