Fix Yes/No flag dtype in notebooks 4.2-4.5 for pandas 3 - #19
Merged
Conversation
The 4.x notebooks set a Yes/No option flag on a case CSV, e.g. gen.loc[mask, "BinaryCommitment"] = "Yes". When that column is empty in the case file, pandas reads it as all-NaN float64. pandas 3 raises TypeError: Invalid value 'Yes' for dtype 'float64' instead of silently upcasting, so the scheduled submodule-bump job failed at notebook 4.2 once the fresh conda build pulled pandas 3. Cast the target column to object before the assignment. This is a no-op where the column already holds strings (4.3). Verified against openTEPES master tip 4ec96bd4 with pandas 3.0.3 on Python 3.12: 4.2, 4.3, 4.4 and 4.5 all solve with no error cells.
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.
The 4.x notebooks set a Yes/No option flag on a case CSV before solving, e.g.
gen.loc[mask, "BinaryCommitment"] = "Yes". When that column is empty in the case file, pandas reads it as all-NaNfloat64. pandas 3 raisesTypeError: Invalid value 'Yes' for dtype 'float64'instead of silently upcasting, so the scheduled submodule-bump job failed at notebook 4.2 once the fresh conda build pulled pandas 3. Notebooks 4.4 and 4.5 hit the same wall next; 4.3 works today only because its column already holds strings.This casts the target column to
objectbefore the assignment (a no-op where the column is already object).Verified against openTEPES master tip
4ec96bd4with pandas 3.0.3 on Python 3.12: 4.2, 4.3, 4.4 and 4.5 all solve with no error cells (200.02 / 161.603 / 197.32 / 191.141 MEUR).