Skip to content

Accept datetime / date for start_time and end_time (#44, #53)#89

Merged
nick-gorman merged 3 commits into
masterfrom
accept-datetime-inputs
May 25, 2026
Merged

Accept datetime / date for start_time and end_time (#44, #53)#89
nick-gorman merged 3 commits into
masterfrom
accept-datetime-inputs

Conversation

@nick-gorman
Copy link
Copy Markdown
Member

Summary

Cherry-picks Matt's two PR-#67 commits that taught the public NEMOSIS API to accept datetime.datetime and datetime.date for start_time / end_time, not just "YYYY/MM/DD HH:MM:SS" strings. Closes #44 and #53.

Public API after this PR:

  • str — legacy "YYYY/MM/DD HH:MM:SS" format, unchanged
  • datetime (timezone-naive) — used verbatim; tz-aware datetimes raise ValueError (the conversion isn't implemented since the contract is "treated as market time")
  • date — converted to midnight. end_time resolves to midnight at the start of the next day so a request bounded by a date covers the whole of that date

Commits

  1. bad82bc Allow start_date to be dt.datetime — Matt's 34fecd4, cherry-picked with Matt's authorship preserved
  2. 691bbb1 Allow passing date as start_time and end_time — Matt's 539670b, cherry-picked with Matt's authorship preserved
  3. 8f11360 Fix dispatch_date_setup / dispatch_half_hour_setup to accept datetime inputs, and add end-to-end coverage — my follow-up

Conflict resolutions during cherry-pick

Bug Matt's PR didn't catch (fixed here)

dispatch_date_setup and dispatch_half_hour_setup in query_wrappers.py are setup-function wrappers used by _set_up_dynamic_compilers. They run BEFORE _parse_datetime_py is called in the compilers, and both still called datetime.strptime(start_time, ...) directly — so passing a datetime or date to any table that routes through them (BIDDAYOFFER_D, BIDPEROFFER_D, MNSP_DAYOFFER, MNSP_PEROFFER, MNSP_INTERCONNECTOR) raised TypeError: strptime() argument 1 must be str, not datetime.datetime. Both wrappers now route through parse_datetime_py at the start, so they accept any of the three input shapes.

Departures from Matt's design

  • Kept the _downloader.X module reference in static_downloader_map rather than switching to direct function imports. The rest of the file uses underscore-aliased module imports throughout.
  • Dropped the "_downloader.download_xml": download_xml key — PR Rename download_xl → download_xlsx, drop dead dict keys #84 already removed it as dead.
  • Did not pull in Matt's net-hitting test_dt_not_string tests in tests/test_data_fetch_methods.py. That whole file was deleted by PR Port test suite to offline fixture-based architecture #72. Offline-fixture replacements in tests/end_to_end_table_tests/test_datetime_inputs.py cover the same behaviour without hitting real AEMO.

Tests

tests/test_date_generators.py::TestParseDatetimePy — Matt's unit tests, 5 cases (datetime, tz-aware datetime, valid string, invalid string, date with midnight='start' and midnight='end').

tests/end_to_end_table_tests/test_datetime_inputs.py — 5 new offline-fixture tests:

  • test_dynamic_data_compiler_accepts_datetime
  • test_dynamic_data_compiler_accepts_date — verifies date end_time resolves to start-of-next-day
  • test_cache_compiler_accepts_datetime
  • test_cache_compiler_accepts_date
  • test_dispatch_date_setup_path_accepts_datetime — regression test for the bug above

Part of the PR #67 breakdown (#9 of ~10).

Test plan

  • uv run pytest tests/test_date_generators.py tests/end_to_end_table_tests/test_datetime_inputs.py — 33 pass
  • uv run pytest — full suite 399 passed / 1 skipped (no regressions)
  • CI matrix (3.10–3.14 × ubuntu/windows/macos)

🤖 Generated with Claude Code

mdavis-xyz and others added 3 commits May 25, 2026 15:08
Adapted from Matt's 34fecd4 via cherry-pick.

Resolved conflicts:
- src/nemosis/data_fetch_methods.py: kept HEAD's underscore-aliased
  module imports (project convention), but adopted Matt's direct
  filter_on_column_value import since both call sites changed.
  Kept HEAD's static_downloader_map with download_xlsx (PR #84 rename)
  and no "_downloader.download_xml" dead key (PR #84 cleanup).
- src/nemosis/custom_tables.py: kept Matt's parse_datetime_py call
  but retained HEAD's pandas freq="5min" (PR #81 deprecation fix).
- tests/test_data_fetch_methods.py: dropped Matt's net-hitting tests;
  the file was deleted by PR #72 in favour of offline-fixture tests.
  Equivalent coverage will be added in the follow-up commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adapted from Matt's 539670b via cherry-pick.

Resolved conflict in src/nemosis/custom_tables.py: kept Matt's
midnight='start' / midnight='end' arguments for parse_datetime_py
but retained HEAD's pandas freq='5min' (PR #81 deprecation fix).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
inputs, and add end-to-end coverage

Matt's PR #67 commits taught dynamic_data_compiler / cache_compiler to
accept datetime and date inputs, but missed two setup-function wrappers
in query_wrappers.py that still called datetime.strptime() directly.
That broke any datetime input flowing through BIDDAYOFFER_D /
BIDPEROFFER_D / MNSP_DAYOFFER / MNSP_PEROFFER / MNSP_INTERCONNECTOR
(uses dispatch_date_setup) or MNSP_PEROFFER (uses
dispatch_half_hour_setup).

Both wrappers now route their inputs through parse_datetime_py so they
accept any of the three input shapes (str / datetime / date), matching
the public-API contract.

Also adds tests/end_to_end_table_tests/test_datetime_inputs.py with 5
end-to-end tests covering the offline-fixture-driven equivalents of
Matt's now-deleted tests/test_data_fetch_methods.py additions: datetime
and date inputs through dynamic_data_compiler and cache_compiler, plus
a BIDDAYOFFER_D regression test that exercises the dispatch_date_setup
path that this commit fixes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@nick-gorman nick-gorman merged commit c7ac421 into master May 25, 2026
16 checks passed
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.

Add 1s data to DispatchPrice

2 participants