Skip to content

Commit

Permalink
Merge pull request #2935 from materialsproject/pandas-v2-fixes
Browse files Browse the repository at this point in the history
Fix breaking changes from pandas v2
  • Loading branch information
janosh authored Apr 4, 2023
2 parents 1e9119a + 267601a commit cdeb0e6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
8 changes: 4 additions & 4 deletions pymatgen/analysis/magnetism/heisenberg.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,13 @@ def _get_exchange_df(self):
ex_row.at[sgraph_index, j_ji] -= s_i * s_j

# Ignore the row if it is a duplicate to avoid singular matrix
if ex_mat.append(ex_row)[j_columns].equals(
ex_mat.append(ex_row)[j_columns].drop_duplicates(keep="first")
):
# Create a temporary DataFrame with the new row
temp_df = pd.concat([ex_mat, ex_row], ignore_index=True)
if temp_df[j_columns].equals(temp_df[j_columns].drop_duplicates(keep="first")):
e_index = self.ordered_structures.index(sgraph.structure)
ex_row.at[sgraph_index, "E"] = self.energies[e_index]
sgraph_index += 1
ex_mat = ex_mat.append(ex_row)
ex_mat = pd.concat([ex_mat, ex_row], ignore_index=True)
# if sgraph_index == num_nn_j: # check for zero columns
# zeros = [b for b in (ex_mat[j_columns] == 0).all(axis=0)]
# if True in zeros:
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/lammps/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def disassemble(self, atom_labels=None, guess_element=True, ff_label="ff_map"):
for um, s in zip(unique_masses, symbols):
masses.loc[masses["mass"] == um, "element"] = s
if atom_labels is None: # add unique labels based on elements
for el, vc in masses["element"].value_counts().iteritems():
for el, vc in masses["element"].value_counts().items():
masses.loc[masses["element"] == el, "label"] = [f"{el}{c}" for c in range(1, vc + 1)]
assert masses["label"].nunique(dropna=False) == len(masses), "Expecting unique atom label for each type"
mass_info = [(row.label, row.mass) for row in masses.itertuples()]
Expand Down
20 changes: 6 additions & 14 deletions pymatgen/io/qchem/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1368,13 +1368,7 @@ def _read_optimization_data(self):
self.data["energy_trajectory"] = []
if read_pattern(self.text, {"key": r"Error in back_transform"}, terminate_on_match=True).get("key") == [[]]:
self.data["errors"] += ["back_transform_error"]
elif read_pattern(
self.text,
{"key": r"pinv\(\)\: svd failed"},
terminate_on_match=True,
).get(
"key"
) == [[]]:
elif read_pattern(self.text, {"key": r"pinv\(\)\: svd failed"}, terminate_on_match=True).get("key") == [[]]:
self.data["errors"] += ["svd_failed"]
else:
real_energy_trajectory = np.zeros(len(temp_energy_trajectory))
Expand Down Expand Up @@ -2668,24 +2662,22 @@ def parse_perturbation_energy(lines: list[str]) -> list[pd.DataFrame]:
Parse the perturbation energy section of NBO output.
Args:
lines: QChem output lines.
lines: QChem output lines.
Returns:
Data frame of formatted output.
Data frame of formatted output.
Raises:
RuntimeError
RuntimeError
"""
no_failures = True
e2_dfs = []

while no_failures:
# 2nd order perturbation theory analysis
try:
lines = jump_to_header(
lines,
"SECOND ORDER PERTURBATION THEORY ANALYSIS OF FOCK MATRIX IN NBO BASIS",
)
header_str = "SECOND ORDER PERTURBATION THEORY ANALYSIS OF FOCK MATRIX IN NBO BASIS"
lines = jump_to_header(lines, header_str)
except RuntimeError:
no_failures = False

Expand Down

0 comments on commit cdeb0e6

Please sign in to comment.