Repository navigation
Make tutorial helpers work with pandas 1.5 and pandas 3 - #28
Merged
Merged
Conversation
Parse the Collector output index with index.map(pd.Timestamp) so the
first bare-date row ("2012-06-01") doesn't fix the inferred format for
later rows with times, and use the 'h' resample alias ('H' was removed
in pandas 3).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ipykernel 7 now depends on nest-asyncio2 instead of nest_asyncio, so the notebooks' `import nest_asyncio` fails in a fresh environment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Four lines in the tutorial helpers, so they work with both pandas 1.5 and pandas 3, plus one line in the CI environment:
tutorials/power_balance/functions_T1.py(2×) andtutorials/physical_congestion/functions_T3.py(1×):result_pd_df.index = pd.to_datetime(result_pd_df.index)→result_pd_df.index = result_pd_df.index.map(pd.Timestamp)tutorials/power_balance/functions_T1.py:resample('H')→resample('h')environment.yml: addnest-asyncio. Separate commit, unrelated to pandas: ipykernel 7 now depends onnest-asyncio2instead ofnest_asyncio, so in a fresh environment the notebooks'import nest_asynciofailed and every test errored.devhas the same problem; its last green run was in June, before this change.Why
2012-06-01) and later rows with a time (2012-06-01 00:15:00). pandas ≥ 2 infers one format from the first value, sopd.to_datetimefails withValueError: unconverted data remains ... " 00:15:00".index.map(pd.Timestamp)parses each value on its own.'H'frequency alias.check-example-compatibility.yamlruns this repo'sdevtests against Illuminator PR branches. The Illuminator Python 3.14 + pandas 3 upgrade (issue 259, branch259) can't pass that check until this is indev.pandas 1.5 / 3 compatibility
format="mixed"(the fix used in Update Python version from 3.11 to 3.14 #25) doesn't exist in pandas 1.5.3, which the PyPI release ofilluminator(3.1b0) pins and this repo's CI installs.index.map(pd.Timestamp)works in both and returns aDatetimeIndex.'h'is accepted by pandas 1.5 as well.pytest -vsuite passes on Python 3.12 + pandas 3.1.1 + Illuminator branch259. This PR's CI covers pandas 1.5 (PyPI illuminator).Relation to #25
Supersedes only the helper part of the closed #25. That PR also moved the env to Python 3.14 + pandas 3 +
illuminator @ git…@259, which is left out here (see follow-ups).Follow-ups (not in this PR)
nest_asyncio(import nest_asyncio/nest_asyncio.apply()) from the notebooks, together with the Python 3.14 / pandas 3 env move from Update Python version from 3.11 to 3.14 #25, after an Illuminator release that includes the newSimulation.run()fix (runs mosaik in a worker thread when Jupyter already has an event loop). The published illuminator still needsnest_asyncio, so it stays for now. On Python 3.14,nest_asynciogives silently wrong simulation results. Note that the in-progress branchestutorial-5,tutorial-5-ide-integrationandide-case-finaladd more notebooks that use it.tutorials/residential/Illuminator_BSc_Tutorial.ipynb(~line 443):pd.to_datetime(df_latest5['date'], errors='coerce')has the same mixed-format problem. Under pandas 3 every row after the first becomesNaT(checked:['2012-06-01', '2012-06-01 00:15:00']→[Timestamp('2012-06-01'), NaT]). Not covered by the test suite.🤖 Generated with Claude Code