Skip to content

fix: replace deprecated datetime.utcnow() in Elexon plotting and tests#414

Open
onurege3467 wants to merge 1 commit intoopenclimatefix:mainfrom
onurege3467:fix/datetime-utc-deprecation
Open

fix: replace deprecated datetime.utcnow() in Elexon plotting and tests#414
onurege3467 wants to merge 1 commit intoopenclimatefix:mainfrom
onurege3467:fix/datetime-utc-deprecation

Conversation

@onurege3467
Copy link
Copy Markdown

Summary

Replace deprecated datetime.utcnow() with timezone-aware datetime.now(UTC) in Elexon plotting code and tests, ensuring Python 3.12+ compatibility.

Root Cause

datetime.utcnow() is deprecated in Python 3.12+ and emits deprecation warnings. The project specifies requires-python = ">=3.12", so this should use the timezone-aware alternative.

Changes

  • src/plots/elexon_plots.py: from datetime import ... UTC + datetime.now(UTC)
  • tests/test_elexon_plot.py: from datetime import ... UTC + datetime.now(UTC)

Why This Is Safe

The new call returns a timezone-aware datetime in the same UTC offset that datetime.utcnow() returned as naive. All start/end datetime calculations remain functionally equivalent. No test logic is changed — only the now reference value is updated.

Testing

  • Pre-commit checks pass
  • Pre-push checks pass (lint + TypeScript)

Related

Python 3.12+ deprecates datetime.utcnow(). Replaced with
datetime.now(UTC) in both elexon_plots.py and its test file,
preserving existing behavior for start/end datetime calculations.

- src/plots/elexon_plots.py: import UTC, use datetime.now(UTC)
- tests/test_elexon_plot.py: import UTC, use datetime.now(UTC)

Fixes openclimatefix#403

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Replace deprecated datetime.utcnow() in Elexon plotting and tests

1 participant