Skip to content

Commit

Permalink
Dedup numpydependency in pyproject (#3970)
Browse files Browse the repository at this point in the history
* dedup numpy dep as pointed out by @DanielYang59's 71f5245#r144995852

* fix some ruff PERF401
  • Loading branch information
janosh authored Aug 3, 2024
1 parent 976942c commit 380a81b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 36 deletions.
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ dependencies = [
"matplotlib>=3.8",
"monty>=2024.7.29",
"networkx>=2.2",
'numpy>=1.25.0,<2.0 ; platform_system == "Windows"',
'numpy>=1.25.0 ; platform_system != "Windows"',
"numpy>=1.25.0 ; platform_system != 'Windows'",
"numpy>=1.25.0,<2.0 ; platform_system == 'Windows'",
"palettable>=3.3.3",
"pandas>=2",
"plotly>=4.5.0",
Expand All @@ -73,8 +73,6 @@ dependencies = [
"tabulate>=0.9",
"tqdm>=4.60",
"uncertainties>=3.1.4",
'numpy>=1.25.0 ; platform_system != "Windows"',
'numpy>=1.25.0,<2.0 ; platform_system == "Windows"',
]
version = "2024.7.18"

Expand Down Expand Up @@ -217,7 +215,7 @@ ignore = [
"PLR0912", # too many branches
"PLR0913", # too many arguments
"PLR0915", # too many statements
"PLR2004", # magic values in comparison
"PLR2004", # magic-value-comparison TODO fix these
"PLW2901", # Outer for loop variable overwritten by inner assignment target
"PT013", # pytest-incorrect-pytest-import
"SIM105", # Use contextlib.suppress() instead of try-except-pass
Expand All @@ -235,7 +233,9 @@ docstring-code-format = true

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"tests/**" = ["ANN201", "D", "PLR0124"]
# PLR2004: magic-value-comparison
# PLR6301: no-self-use
"tests/**" = ["ANN201", "D", "PLR0124", "PLR2004", "PLR6301"]
"src/pymatgen/analysis/*" = ["D"]
"src/pymatgen/io/*" = ["D"]
"dev_scripts/*" = ["D"]
Expand Down
7 changes: 3 additions & 4 deletions src/pymatgen/symmetry/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,9 @@ def _get_symmetry(self) -> tuple[NDArray, NDArray]:
# [1e-4, 2e-4, 1e-4]
# (these are in fractional coordinates, so should be small denominator
# fractions)
_translations: list = []
for trans in dct["translations"]:
_translations.append([float(Fraction(c).limit_denominator(1000)) for c in trans])
translations: NDArray = np.array(_translations)
translations: NDArray = np.array(
[[float(Fraction(c).limit_denominator(1000)) for c in trans] for trans in dct["translations"]]
)

# Fractional translations of 1 are more simply 0
translations[np.abs(translations) == 1] = 0
Expand Down
6 changes: 1 addition & 5 deletions src/pymatgen/symmetry/kpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,11 +1343,7 @@ def _choose_path(
# Choose remaining unconnected key points for k-path. The ones that remain are
# those with inversion symmetry. Connect them to gamma.

unconnected = []

for idx in range(len(key_points_inds_orbits)):
if idx not in point_orbits_in_path:
unconnected.append(idx)
unconnected = [idx for idx in range(len(key_points_inds_orbits)) if idx not in point_orbits_in_path]

for ind in unconnected:
connect = False
Expand Down
26 changes: 10 additions & 16 deletions src/pymatgen/symmetry/maggroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,15 @@ def _parse_lattice(b):
return None
raw_lattice = [b[i : i + 4] for i in range(0, len(b), 4)]

lattice = []

for r in raw_lattice:
lattice.append(
{
"vector": [r[0] / r[3], r[1] / r[3], r[2] / r[3]],
"str": f"({Fraction(r[0] / r[3]).limit_denominator()},"
f"{Fraction(r[1] / r[3]).limit_denominator()},"
f"{Fraction(r[2] / r[3]).limit_denominator()})+",
}
)

return lattice
return [
{
"vector": [r[0] / r[3], r[1] / r[3], r[2] / r[3]],
"str": f"({Fraction(r[0] / r[3]).limit_denominator()},"
f"{Fraction(r[1] / r[3]).limit_denominator()},"
f"{Fraction(r[2] / r[3]).limit_denominator()})+",
}
for r in raw_lattice
]

def _parse_transformation(b):
"""Parse compact binary representation into transformation between OG and BNS settings."""
Expand Down Expand Up @@ -559,9 +555,7 @@ def _write_all_magnetic_space_groups_to_file(filename):
"http://stokes.byu.edu/iso/magnetic_data.txt\n"
"Used with kind permission from Professor Branton Campbell, BYU\n\n"
)
all_msgs = []
for i in range(1, 1652):
all_msgs.append(MagneticSpaceGroup(i))
all_msgs = list(map(MagneticSpaceGroup, range(1, 1652)))
for msg in all_msgs:
out += f"\n{msg.data_str()}\n\n--------\n"
with open(filename, mode="w") as file:
Expand Down
3 changes: 1 addition & 2 deletions src/pymatgen/symmetry/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ def __str__(self) -> str:
row = [str(idx), site.species_string]
row.extend([f"{j:>10.6f}" for j in site.frac_coords])
row.append(self.wyckoff_symbols[idx])
for key in keys:
row.append(props[key][idx])
row += [props[key][idx] for key in keys]
data.append(row)
outs.append(tabulate(data, headers=["#", "SP", "a", "b", "c", "Wyckoff", *keys]))
return "\n".join(outs)
Expand Down
4 changes: 1 addition & 3 deletions tests/analysis/test_local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,6 @@ def test_weighted_cn(self):

def test_weighted_cn_no_oxid(self):
cnn = CrystalNN(weighted_cn=True)
cn_array = []
# fmt: off
expected_array = [
5.8962, 5.8996, 5.8962, 5.8996, 5.7195, 5.7195, 5.7202, 5.7194, 4.0012, 4.0012,
Expand All @@ -1211,8 +1210,7 @@ def test_weighted_cn_no_oxid(self):
]
# fmt: on
struct = self.lifepo4.copy().remove_oxidation_states()
for idx in range(len(struct)):
cn_array.append(cnn.get_cn(struct, idx, use_weights=True))
cn_array = [cnn.get_cn(struct, idx, use_weights=True) for idx in range(len(struct))]

assert_allclose(expected_array, cn_array, 2)

Expand Down

0 comments on commit 380a81b

Please sign in to comment.