Skip to content

feature: add apply() and timezone-awareness to AvailableAt#831

Merged
lschilders merged 7 commits intorelease/v4.0.0from
feature/available-at-apply
Mar 9, 2026
Merged

feature: add apply() and timezone-awareness to AvailableAt#831
lschilders merged 7 commits intorelease/v4.0.0from
feature/available-at-apply

Conversation

@lschilders
Copy link
Copy Markdown
Collaborator

@lschilders lschilders commented Mar 9, 2026

This pull request introduces a significant refactor and enhancement of the AvailableAt type in the openstef_core.types module, transitioning from a timedelta-based API to a more expressive and robust representation using day offsets, time-of-day, and optional timezone support. The update improves clarity, enables precise timezone-aware calculations (including DST handling), and modernizes the API. Extensive new and updated tests ensure correctness and backward compatibility, including legacy string format support.

Major enhancements to AvailableAt:

  • Refactored AvailableAt to use explicit day_offset, time_of_day, and optional tzinfo instead of a timedelta, with a new string format (DnTHHMM[tz]) and backward-compatible parsing for the legacy format. This allows for clear, direct specification of availability cutoffs and supports timezones via IANA names or UTC/Z notation.
  • Added methods apply and apply_index to compute availability cutoffs for single datetimes and Pandas DatetimeIndex, with correct handling of timezones and DST transitions.
  • Updated the string representation, parsing, and validation logic to reject positive day offsets and invalid formats, improving robustness and error messages.

Integration and usage updates:

  • Updated TimeSeriesDataset.filter_by_available_at and related code to use the new AvailableAt.apply_index method, ensuring correct cutoff calculations and simplifying the logic.
  • Updated all usage sites and tests to use the new AvailableAt constructor and API, replacing legacy timedelta-based calls. [1] [2] [3] [4]

Expanded and improved test coverage:

  • Added comprehensive unit tests for the new AvailableAt API, including round-trip string parsing, DST-aware cutoff handling, legacy format support, timezone parsing (including error cases), and edge cases like positive offsets and invalid input.
  • Added a DST transition test to ensure correct cutoff calculation across daylight saving changes.

Additional improvements:

  • Improved documentation and examples in the AvailableAt docstring, clarifying usage, parameters, and expected behavior.
  • Minor imports and typing updates across modules and tests to support new functionality and typing requirements. [1] [2] [3] [4]

These changes collectively modernize the handling of data availability cutoffs in the codebase, making it more expressive, robust, and timezone-aware.

Change references: [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

@lschilders lschilders requested a review from a team March 9, 2026 09:33
@github-actions github-actions Bot added the feature New feature or request label Mar 9, 2026
egordm
egordm previously approved these changes Mar 9, 2026
Copy link
Copy Markdown
Collaborator

@egordm egordm left a comment

Choose a reason for hiding this comment

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

LGTM!

Signed-off-by: lschilders <lars.schilders@alliander.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 9, 2026

Copy link
Copy Markdown
Collaborator

@egordm egordm left a comment

Choose a reason for hiding this comment

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

LGTM!

@lschilders lschilders merged commit 573d041 into release/v4.0.0 Mar 9, 2026
4 checks passed
@lschilders lschilders deleted the feature/available-at-apply branch March 9, 2026 13:51
fleur-petit pushed a commit to fleur-petit/openstef that referenced this pull request Mar 26, 2026
)

* feature: add apply() to AvailableAt and tz-aware option

* feature: refactor AvailableAt to use day_offset and time_of_day rather than lag_from_day

* feature: (de)serialization support for tz-aware AvailableAt

* feature: improved docstring

* feature: add tests for apply_index

Signed-off-by: lschilders <lars.schilders@alliander.com>

---------

Signed-off-by: lschilders <lars.schilders@alliander.com>
Signed-off-by: Fleur Petit <fleur.petit@alliander.com>
fleur-petit pushed a commit to fleur-petit/openstef that referenced this pull request Mar 26, 2026
)

* feature: add apply() to AvailableAt and tz-aware option

* feature: refactor AvailableAt to use day_offset and time_of_day rather than lag_from_day

* feature: (de)serialization support for tz-aware AvailableAt

* feature: improved docstring

* feature: add tests for apply_index

Signed-off-by: lschilders <lars.schilders@alliander.com>

---------

Signed-off-by: lschilders <lars.schilders@alliander.com>
Signed-off-by: Fleur Petit <fleur.petit@alliander.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants