From 1fa81bdd6b7eecfd1093e4d2ee97e4cf269fe0bf Mon Sep 17 00:00:00 2001 From: Erik Alvarez Date: Mon, 20 Jul 2026 12:29:05 +0200 Subject: [PATCH] Cast Yes/No flag columns to object before writing in notebooks 4.2-4.5 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. --- notebooks/4.2-Unit-Commitment.ipynb | 1 + notebooks/4.3-Transmission-Expansion-Planning.ipynb | 1 + notebooks/4.4-Generation-Expansion-Planning.ipynb | 1 + notebooks/4.5-Optimal-Transmission-Switching.ipynb | 1 + 4 files changed, 4 insertions(+) diff --git a/notebooks/4.2-Unit-Commitment.ipynb b/notebooks/4.2-Unit-Commitment.ipynb index ebee1e5..fc0de5c 100644 --- a/notebooks/4.2-Unit-Commitment.ipynb +++ b/notebooks/4.2-Unit-Commitment.ipynb @@ -174,6 +174,7 @@ "\n", "gen = pd.read_csv(os.path.join(DIR, CaseName, \"oT_Data_Generation_9n.csv\"))\n", "committed = [\"OCGT_1\", \"OCGT_2\", \"OCGT_3\", \"CCGT_1\", \"CCGT_2\"]\n", + "gen[\"BinaryCommitment\"] = gen[\"BinaryCommitment\"].astype(object) # let the column hold the Yes/No flag\n", "gen.loc[gen[gen.columns[0]].isin(committed), \"BinaryCommitment\"] = \"Yes\"\n", "gen.to_csv(os.path.join(DIR, CaseName, \"oT_Data_Generation_9n.csv\"), index=False)\n", "gen.loc[gen[gen.columns[0]].isin(committed), [gen.columns[0], \"Technology\", \"BinaryCommitment\"]]" diff --git a/notebooks/4.3-Transmission-Expansion-Planning.ipynb b/notebooks/4.3-Transmission-Expansion-Planning.ipynb index d22dcd9..6b1e05d 100644 --- a/notebooks/4.3-Transmission-Expansion-Planning.ipynb +++ b/notebooks/4.3-Transmission-Expansion-Planning.ipynb @@ -142,6 +142,7 @@ "\n", "net = pd.read_csv(os.path.join(DIR, CaseName, \"oT_Data_Network_9n.csv\"))\n", "cand = (net[\"InitialNode\"] == \"Node_1\") & (net[\"FinalNode\"] == \"Node_4\") & (net[\"Circuit\"] == \"dc1\")\n", + "net[\"BinaryInvestment\"] = net[\"BinaryInvestment\"].astype(object) # let the column hold the Yes/No flag\n", "net.loc[cand, \"BinaryInvestment\"] = \"Yes\"\n", "net.to_csv(os.path.join(DIR, CaseName, \"oT_Data_Network_9n.csv\"), index=False)\n", "net.loc[cand, [\"InitialNode\", \"FinalNode\", \"Circuit\", \"FixedInvestmentCost\", \"BinaryInvestment\"]]" diff --git a/notebooks/4.4-Generation-Expansion-Planning.ipynb b/notebooks/4.4-Generation-Expansion-Planning.ipynb index 6acd2fc..b01e286 100644 --- a/notebooks/4.4-Generation-Expansion-Planning.ipynb +++ b/notebooks/4.4-Generation-Expansion-Planning.ipynb @@ -154,6 +154,7 @@ "gen.loc[cand, \"FixedChargeRate\"] = 0.05 # annualises the investment cost\n", "gen.loc[cand, \"InvestmentUp\"] = 1\n", "gen.loc[cand, \"InvestmentLo\"] = 0\n", + "gen[\"BinaryInvestment\"] = gen[\"BinaryInvestment\"].astype(object) # let the column hold the Yes/No flag\n", "gen.loc[cand, \"BinaryInvestment\"] = \"Yes\"\n", "gen.to_csv(os.path.join(DIR, CaseName, \"oT_Data_Generation_9n.csv\"), index=False)\n", "gen.loc[cand, [gen.columns[0], \"Technology\", \"FixedInvestmentCost\", \"FixedChargeRate\", \"InvestmentUp\"]]" diff --git a/notebooks/4.5-Optimal-Transmission-Switching.ipynb b/notebooks/4.5-Optimal-Transmission-Switching.ipynb index 2cf3a3b..410305d 100644 --- a/notebooks/4.5-Optimal-Transmission-Switching.ipynb +++ b/notebooks/4.5-Optimal-Transmission-Switching.ipynb @@ -172,6 +172,7 @@ "\n", "net = pd.read_csv(os.path.join(DIR, CaseName, \"oT_Data_Network_9n.csv\"))\n", "switchable = net[\"InitialNode\"].isin([\"Node_1\", \"Node_2\"])\n", + "net[\"Switching\"] = net[\"Switching\"].astype(object) # let the column hold the Yes/No flag\n", "net.loc[switchable, \"Switching\"] = \"Yes\"\n", "net.to_csv(os.path.join(DIR, CaseName, \"oT_Data_Network_9n.csv\"), index=False)\n", "net.loc[switchable, [\"InitialNode\", \"FinalNode\", \"Circuit\", \"Switching\"]]"