Skip to content
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

Fix chained offset bug #5031

Merged
merged 6 commits into from
Aug 8, 2022
Merged

Conversation

MetRonnie
Copy link
Member

@MetRonnie MetRonnie commented Aug 1, 2022

These changes close #4908

Fix bug where specifying multiple datetime offsets would not obey the given order.

E.g. final cycle point = +P1M-P1D would lead to it calculating icp - P1D + P1M (smallest unit to largest unit order) instead of icp + P1M - P1D (given order).

Requirements check-list

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Applied any dependency changes to both setup.cfg and conda-environment.yml.
  • Appropriate tests are included (unit and/or functional).
  • Appropriate change log entry included.
  • No documentation update required.
  • [if bugfix] PRs raised to both master and the relevant bugfix branch.

@MetRonnie MetRonnie added the bug Something is wrong :( label Aug 1, 2022
@MetRonnie MetRonnie added this to the cylc-8.0.1 milestone Aug 1, 2022
@MetRonnie MetRonnie self-assigned this Aug 1, 2022
Comment on lines +133 to +134
context_start_point, _ = self._get_point_from_expression(
context_start_point, None)
Copy link
Member

@oliver-sanders oliver-sanders Aug 1, 2022

Choose a reason for hiding this comment

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

FYI: This is subjective, the way this was done before saved an unnecessary assignment.

Copy link
Member

@oliver-sanders oliver-sanders left a comment

Choose a reason for hiding this comment

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

LGTM

cylc/flow/time_parser.py Outdated Show resolved Hide resolved
Comment on lines +377 to +379
ptslist.append(cpoint)
if cpoint == min(ptslist):
min_entry = point
Copy link
Member

Choose a reason for hiding this comment

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

>>> min([1, None])
Traceback ...
TypeError

How has this one not blown up before?

Hole in the tests?

Copy link
Member Author

@MetRonnie MetRonnie Aug 2, 2022

Choose a reason for hiding this comment

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

Not sure. Perhaps it is very unlikely to be hit. It's difficult to tell because the self._get_point_from_expression() method probably does too much for a single method (no unit tests to tell us what it's supposed to be doing).

As for Mypy not flagging the appending None to List[TimePoint], I think that might be due to the fact we're missing py.typed in isodatetime (added in metomi/isodatetime#203)

@oliver-sanders oliver-sanders changed the base branch from master to 8.0.x August 2, 2022 09:23
@MetRonnie MetRonnie changed the title Fix conjugate offset bug Fix chained offset bug Aug 2, 2022
@MetRonnie MetRonnie deleted the branch cylc:8.0.x August 3, 2022 11:58
@MetRonnie MetRonnie closed this Aug 3, 2022
@MetRonnie
Copy link
Member Author

oops

@MetRonnie MetRonnie reopened this Aug 3, 2022
@MetRonnie
Copy link
Member Author

(Fast test failure on MacOS due to Codecov uploader failing again...)

@@ -355,78 +359,69 @@ def _get_interval_from_expression(
def _get_min_from_expression(
self,
expr: str,
context: 'TimePoint'
context: Optional['TimePoint']
) -> str:
Copy link
Member

Choose a reason for hiding this comment

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

A docstring might have been nice?

Copy link
Member Author

Choose a reason for hiding this comment

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

(Sighing) Yes it would have. When someone figures out what this is doing it would also be a good idea to add a unit test

Copy link
Member

@wxtim wxtim Aug 4, 2022

Choose a reason for hiding this comment

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

Out of scope to be fair.

I wrote a longer comment that I also deemed OOS about how many of these might be better as static methods fed values as args to enable nice unit testing.

allow implicit tasks = True
[scheduling]
initial cycle point = {icp}
final cycle point = {fcp_expr}
Copy link
Member

@wxtim wxtim Aug 4, 2022

Choose a reason for hiding this comment

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

I'm not sure if _parse_chain_expression is used elsewhere, but if it is, it's worth noting that this only works if the sum of the durations > 0.

Also, should

        ('2000-01-01T00:00', '+PT6H-PT1S', '2000-01-01T05:59'),

Work?

Might be worth some additional tests here for intervals not P1D and P1M?

Copy link
Member Author

Choose a reason for hiding this comment

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

  • I've added more tests
  • I've opened an issue for the +PT6H+PT1S bug: Chain offset expression with time units does not work #5047
  • parse_chain_expression() works for net < 0 durations but that does not produce a valid final cycle point, because it is before the initial cycle point (already a tested scenario)

@MetRonnie MetRonnie deleted the conjugate-duration-bug branch August 8, 2022 09:48
oliver-sanders pushed a commit to oliver-sanders/cylc-flow that referenced this pull request Aug 15, 2022
Fix conjugate duration bug

* Closes cylc#4908
* Fix bug where specifying multiple datetime offsets would not obey the given order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is wrong :(
Projects
None yet
Development

Successfully merging this pull request may close these issues.

final cycle point offset giving wrong result
3 participants