Skip to content

Commit

Permalink
Fix ValueError: not enough values to unpack in PDPlotter if no unstab…
Browse files Browse the repository at this point in the history
…le entries in PD (#2908)

* fix ValueError: not enough values to unpack (expected 2, got 0)

in PDPlotter: unstable_entries, unstable_coords = zip(*self.pd_plot_data[2].items())

* add test to prevent regression
  • Loading branch information
janosh authored Mar 24, 2023
1 parent c8f9991 commit c6928cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
15 changes: 5 additions & 10 deletions pymatgen/analysis/phase_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -3014,17 +3014,12 @@ def get_marker_props(coords, entries, stable=True):
elif self._dim == 4:
z.append(coord[2])

return {
"x": x,
"y": y,
"z": z,
"texts": texts,
"energies": energies,
"uncertainties": uncertainties,
}
return {"x": x, "y": y, "z": z, "texts": texts, "energies": energies, "uncertainties": uncertainties}

stable_coords, stable_entries = zip(*self.pd_plot_data[1].items())
unstable_entries, unstable_coords = zip(*self.pd_plot_data[2].items())
stable_coords = list(self.pd_plot_data[1])
stable_entries = self.pd_plot_data[1].values()
unstable_entries = list(self.pd_plot_data[2])
unstable_coords = self.pd_plot_data[2].values()

stable_props = get_marker_props(stable_coords, stable_entries)

Expand Down
7 changes: 7 additions & 0 deletions pymatgen/analysis/tests/test_phase_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,13 @@ def setUp(self):
self.plotter_quaternary_mpl = PDPlotter(self.pd_quaternary, backend="matplotlib")
self.plotter_quaternary_plotly = PDPlotter(self.pd_quaternary, backend="plotly")

def test_plot_pd_with_no_unstable(self):
# https://github.com/materialsproject/pymatgen/issues/2885
pd_entries = [PDEntry(comp, 0) for comp in ["Li", "Co", "O"]]
pd = PhaseDiagram(pd_entries)
plotter = PDPlotter(pd, backend="plotly", show_unstable=False)
plotter.get_plot()

def test_pd_plot_data(self):
lines, labels, unstable_entries = self.plotter_ternary_mpl.pd_plot_data
assert len(lines) == 22
Expand Down

0 comments on commit c6928cc

Please sign in to comment.