Skip to content

fix: _as_index() calls to_index() for DataArrays - #897

Merged
FBumann merged 4 commits into
PyPSA:masterfrom
peterhron:fix/timezone-aware-coords
Aug 19, 2026
Merged

fix: _as_index() calls to_index() for DataArrays#897
FBumann merged 4 commits into
PyPSA:masterfrom
peterhron:fix/timezone-aware-coords

Conversation

@peterhron

@peterhron peterhron commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Closes #898 (if applicable).

Changes proposed in this Pull Request

helper in alignment.py uses DataArray.to_index() to retrieve the actual pandas index object instead of re-building it via pd.Index. This fixes regression where timezone-aware indexes cannot be used to build a model.

Unit tests are added to validate that models can be built with timezone-aware coords.

Checklist

  • AI-generated content is marked (see AGENTS.md).
  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in doc.
  • Unit tests for new features were added (if applicable).
  • A note for the release notes doc/release_notes.rst of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.

@codspeed-hq

codspeed-hq Bot commented Aug 18, 2026

Copy link
Copy Markdown

Merging this PR will regress 2 benchmarks

⚡ 6 improved benchmarks
❌ 2 regressed benchmarks
✅ 167 untouched benchmarks
⏩ 175 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory test_to_lp[storage-n=250] 30.3 MB 35.8 MB -15.43%
Memory test_to_lp[nodal_balance-severity=50] 2.9 MB 3.3 MB -12.05%
Memory test_to_lp[nodal_balance-severity=0] 3.4 MB 2.4 MB +41.85%
Memory test_to_lp[milp-n=50] 2.6 MB 2 MB +29.32%
Memory test_build[knapsack-n=100] 5.5 KB 4.7 KB +17.07%
Memory test_to_lp[merge_balance-severity=0] 2.6 MB 2.3 MB +15.59%
Memory test_build[knapsack-n=10000] 830.3 KB 752.2 KB +10.39%
Memory test_to_lp[storage-n=10] 2.9 MB 2.6 MB +10.17%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing peterhron:fix/timezone-aware-coords (33a2f82) with master (f06738e)

Open in CodSpeed

Footnotes

  1. 175 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@peterhron

Copy link
Copy Markdown
Contributor Author

@codspeedbot fix this regression

@peterhron

Copy link
Copy Markdown
Contributor Author

hey, @FBumann @FabianHofmann , tagging you guys since you were the last to touch the related code; could you please briefly check this? Details are in the linked issue, pls let me know whether you find this resolution appropriate.

If so, i'd like to ask for brief assistance with fixing the checks, as this is my first contribution here and i'm not familiar with it. Both the failures are weird to me, and likely transient (but i can't re-run the pipelines to confirm).

I'd think the memory regression is just noise (codspeed also reports 'Different runtime environments detected', which might be the reason). The test failure on 3.11. is unrelated to my changes - Copilot suggested that it's a problem with a flaky version of coptpy. Similar error happened on master today.

Pleaes let me know what you think. Thanks a lot!

@FBumann

FBumann commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Hi @peterhron,
First of all thanks for your Pr. It looks very reviewable and focused to me. We'll get it reviewed soon.

About Codspeed: Yes, Codspeed is quite flaky atm. This won't be a regression.

About the tests: Yes, this isn't from your change. We are investigating an issue with COPT at the moment #899

@FBumann FBumann left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great work! Please add a release note entry, then we are good to go @peterhron.

@FBumann
FBumann self-requested a review August 19, 2026 09:53

@FBumann FBumann left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for your contribution @peterhron

@peterhron

Copy link
Copy Markdown
Contributor Author

Thanks for your contribution @peterhron

thanks for the quick response. I just had to rebase, otherwise the PR should be good to go!

@FBumann
FBumann merged commit 09c34dd into PyPSA:master Aug 19, 2026
24 of 26 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.

timezone-aware coords do not build after version 0.8.0

3 participants