Skip to content

Commit

Permalink
fix type
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Jan 25, 2025
1 parent e13a607 commit 5b00031
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/pymatgen/core/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,17 +414,17 @@ def reduced_composition(self) -> Self:
"""
return self.get_reduced_composition_and_factor()[0]

def get_reduced_composition_and_factor(self) -> tuple[Self, int]:
def get_reduced_composition_and_factor(self) -> tuple[Self, float]:
"""Calculate a reduced composition and factor.
Returns:
A normalized composition and a multiplicative factor, i.e.,
Li4Fe4P4O16 returns (Composition("LiFePO4"), 4).
tuple[Composition, float]: Normalized Composition and multiplicative factor,
i.e. "Li4Fe4P4O16" returns (Composition("LiFePO4"), 4).
"""
factor: int = self.get_reduced_formula_and_factor()[1]
factor: float = self.get_reduced_formula_and_factor()[1]
return self / factor, factor

def get_reduced_formula_and_factor(self, iupac_ordering: bool = False) -> tuple[str, int]:
def get_reduced_formula_and_factor(self, iupac_ordering: bool = False) -> tuple[str, float]:
"""Calculate a reduced formula and factor.
Args:
Expand All @@ -438,14 +438,15 @@ def get_reduced_formula_and_factor(self, iupac_ordering: bool = False) -> tuple[
the elements.
Returns:
tuple[str, int]: A normalized formula and a multiplicative factor,
tuple[str, float]: Normalized formula and multiplicative factor,
i.e., "Li4Fe4P4O16" returns (LiFePO4, 4).
"""
all_int: bool = all(abs(val - round(val)) < type(self).amount_tolerance for val in self.values())
if not all_int:
return self.formula.replace(" ", ""), 1

el_amt_dict: dict[str, int] = {key: round(val) for key, val in self.get_el_amt_dict().items()}
factor: float
formula, factor = reduce_formula(el_amt_dict, iupac_ordering=iupac_ordering)

# Do not "completely reduce" certain formulas
Expand Down

0 comments on commit 5b00031

Please sign in to comment.