Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ValueError: not enough values to unpack in PDPlotter if no unstable entries in PD #2908

Merged
merged 3 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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