Skip to content

Fix timezone handling and midnight rounding issues in forecasts#330

Open
CodeVishal-17 wants to merge 3 commits intoopenclimatefix:mainfrom
CodeVishal-17:main
Open

Fix timezone handling and midnight rounding issues in forecasts#330
CodeVishal-17 wants to merge 3 commits intoopenclimatefix:mainfrom
CodeVishal-17:main

Conversation

@CodeVishal-17
Copy link
Contributor

Description

This PR fixes issues with timestamp handling in the forecasting pipeline, particularly around
timezone-aware inputs and rounding behavior close to midnight.

Specifically:

  • Normalize the input timestamp once in run_forecast, ensuring all downstream logic receives
    a timezone-aware UTC timestamp.
  • Handle timezone-aware and timezone-naive inputs consistently (naive timestamps are assumed
    to be UTC with a deprecation warning).
  • Fix a rounding edge case in predict_tryolabs where timestamps close to midnight could
    produce inconsistent start_date and start_time values.

This avoids subtle bugs and errors when using timezone-aware datetimes or when forecasts are
run close to day boundaries.

Fixes #320

How Has This Been Tested?

  • Manually tested predict_tryolabs with timestamps close to midnight (e.g. 23:40, 23:55)
    to ensure start_date and start_time are derived from the same rounded timestamp.

  • Verified that timezone-aware timestamps (non-UTC) are accepted and handled correctly.

  • Verified that timezone-naive timestamps continue to work and emit a deprecation warning.

  • Checked that behavior for typical daytime timestamps remains unchanged.

  • Yes

If your changes affect data processing, have you plotted any changes? i.e. have you done a quick sanity check?

  • Yes

Checklist:

  • My code follows OCF's coding style guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked my code and corrected any misspellings

@CodeVishal-17
Copy link
Contributor Author

Heads up: the failing CI appears unrelated to the timezone changes in this PR.

The errors are coming from API unit tests failing with:
AttributeError: InferenceClient has no attribute chat_completion,
which looks like a breaking change in the HuggingFace InferenceClient API.

Happy to pin the dependency or update the mocks if that’s desired — let me know what you prefer.

@CodeVishal-17
Copy link
Contributor Author

CI is still failing with:

AttributeError: InferenceClient has no attribute chat_completion

This looks unrelated to the timezone changes in this PR and appears to be due
to a mismatch between the API tests and the current huggingface_hub
InferenceClient API.

I pinned huggingface_hub==0.17.3, but CI still seems to install a version
without chat_completion.

Happy to:
• update the API test mocks, or
• adjust the CI install strategy, or
• leave this to a follow-up PR

— let me know what you’d prefer.

@CodeVishal-17 CodeVishal-17 marked this pull request as ready for review January 27, 2026 08:49
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.

Timezone Handling Awkward

1 participant