Skip to content

Commit

Permalink
refactor dict.update() to use |= operator
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Aug 3, 2024
1 parent c185bd4 commit e3fbc67
Show file tree
Hide file tree
Showing 28 changed files with 387 additions and 477 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,8 @@ def compute_structure_environments(
optimization: optimization algorithm
Returns:
The StructureEnvironments object containing all the information about the coordination
environments in the structure.
StructureEnvironments: contains all the information about the coordination
environments in the structure.
"""
time_init = time.process_time()
if info is None:
Expand Down
6 changes: 3 additions & 3 deletions src/pymatgen/analysis/chempot_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def _get_2d_plot(self, elements: list[Element], label_stable: bool | None, eleme
draw_domains[formula] = pts_2d

layout = plotly_layouts["default_layout_2d"].copy()
layout.update(self._get_axis_layout_dict(elements))
layout |= self._get_axis_layout_dict(elements)
if label_stable:
layout["annotations"] = annotations

Expand Down Expand Up @@ -366,7 +366,7 @@ def _get_3d_plot(
domain_simplexes[formula] = simplexes

layout = plotly_layouts["default_layout_3d"].copy()
layout["scene"].update(self._get_axis_layout_dict(elements))
layout["scene"] |= self._get_axis_layout_dict(elements)
layout["scene"]["annotations"] = None

if label_stable:
Expand Down Expand Up @@ -559,7 +559,7 @@ def _get_annotation(ann_loc: np.ndarray, formula: str) -> dict[str, str | float]
"""Get a Plotly annotation dict given a formula and location."""
formula = htmlify(formula)
annotation = plotly_layouts["default_annotation_layout"].copy()
annotation.update({"x": ann_loc[0], "y": ann_loc[1], "text": formula})
annotation |= {"x": ann_loc[0], "y": ann_loc[1], "text": formula}
if len(ann_loc) == 3:
annotation["z"] = ann_loc[2]
return annotation
Expand Down
5 changes: 1 addition & 4 deletions src/pymatgen/analysis/ferroelectricity/polarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ def zval_dict_from_potcar(potcar) -> dict[str, float]:
potcar: Potcar object
"""
zval_dict = {}
for p in potcar:
zval_dict.update({p.element: p.ZVAL})
return zval_dict
return {p.element: p.ZVAL for p in potcar}


def calc_ionic(site: PeriodicSite, structure: Structure, zval: float) -> np.ndarray:
Expand Down
4 changes: 2 additions & 2 deletions src/pymatgen/analysis/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ def draw_graph_to_file(
d["label"] = f"{d['weight']:.2f} {units}"

# update edge with our new style attributes
g.edges[u, v, k].update(d)
g.edges[u, v, k] |= d

# optionally remove periodic image edges,
# these can be confusing due to periodic boundaries
Expand Down Expand Up @@ -2603,7 +2603,7 @@ def draw_graph_to_file(
d["label"] = f"{d['weight']:.2f} {units}"

# update edge with our new style attributes
g.edges[u, v, k].update(d)
g.edges[u, v, k] |= d

# optionally remove periodic image edges,
# these can be confusing due to periodic boundaries
Expand Down
10 changes: 4 additions & 6 deletions src/pymatgen/analysis/local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ def __init__(

# Update any user preference elemental radii
if el_radius_updates:
self.el_radius.update(el_radius_updates)
self.el_radius |= el_radius_updates

@property
def structures_allowed(self) -> bool:
Expand Down Expand Up @@ -2755,7 +2755,7 @@ def get_type(self, index):
raise ValueError("Index for getting order parameter type out-of-bounds!")
return self._types[index]

def get_parameters(self, index):
def get_parameters(self, index: int) -> list[float]:
"""Get list of floats that represents
the parameters associated
with calculation of the order
Expand All @@ -2764,12 +2764,10 @@ def get_parameters(self, index):
inputted because of processing out of efficiency reasons.
Args:
index (int):
index of order parameter for which associated parameters
are to be returned.
index (int): index of order parameter for which to return associated params.
Returns:
[float]: parameters of a given OP.
list[float]: parameters of a given OP.
"""
if index < 0 or index >= len(self._types):
raise ValueError("Index for getting parameters associated with order parameter calculation out-of-bounds!")
Expand Down
Loading

0 comments on commit e3fbc67

Please sign in to comment.