Skip to content

Commit 380a81b

Browse files
authored
Dedup numpydependency in pyproject (#3970)
* dedup numpy dep as pointed out by @DanielYang59's 71f5245#r144995852 * fix some ruff PERF401
1 parent 976942c commit 380a81b

File tree

6 files changed

+22
-36
lines changed

6 files changed

+22
-36
lines changed

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ dependencies = [
5959
"matplotlib>=3.8",
6060
"monty>=2024.7.29",
6161
"networkx>=2.2",
62-
'numpy>=1.25.0,<2.0 ; platform_system == "Windows"',
63-
'numpy>=1.25.0 ; platform_system != "Windows"',
62+
"numpy>=1.25.0 ; platform_system != 'Windows'",
63+
"numpy>=1.25.0,<2.0 ; platform_system == 'Windows'",
6464
"palettable>=3.3.3",
6565
"pandas>=2",
6666
"plotly>=4.5.0",
@@ -73,8 +73,6 @@ dependencies = [
7373
"tabulate>=0.9",
7474
"tqdm>=4.60",
7575
"uncertainties>=3.1.4",
76-
'numpy>=1.25.0 ; platform_system != "Windows"',
77-
'numpy>=1.25.0,<2.0 ; platform_system == "Windows"',
7876
]
7977
version = "2024.7.18"
8078

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

236234
[tool.ruff.lint.per-file-ignores]
237235
"__init__.py" = ["F401"]
238-
"tests/**" = ["ANN201", "D", "PLR0124"]
236+
# PLR2004: magic-value-comparison
237+
# PLR6301: no-self-use
238+
"tests/**" = ["ANN201", "D", "PLR0124", "PLR2004", "PLR6301"]
239239
"src/pymatgen/analysis/*" = ["D"]
240240
"src/pymatgen/io/*" = ["D"]
241241
"dev_scripts/*" = ["D"]

src/pymatgen/symmetry/analyzer.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,9 @@ def _get_symmetry(self) -> tuple[NDArray, NDArray]:
277277
# [1e-4, 2e-4, 1e-4]
278278
# (these are in fractional coordinates, so should be small denominator
279279
# fractions)
280-
_translations: list = []
281-
for trans in dct["translations"]:
282-
_translations.append([float(Fraction(c).limit_denominator(1000)) for c in trans])
283-
translations: NDArray = np.array(_translations)
280+
translations: NDArray = np.array(
281+
[[float(Fraction(c).limit_denominator(1000)) for c in trans] for trans in dct["translations"]]
282+
)
284283

285284
# Fractional translations of 1 are more simply 0
286285
translations[np.abs(translations) == 1] = 0

src/pymatgen/symmetry/kpath.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,11 +1343,7 @@ def _choose_path(
13431343
# Choose remaining unconnected key points for k-path. The ones that remain are
13441344
# those with inversion symmetry. Connect them to gamma.
13451345

1346-
unconnected = []
1347-
1348-
for idx in range(len(key_points_inds_orbits)):
1349-
if idx not in point_orbits_in_path:
1350-
unconnected.append(idx)
1346+
unconnected = [idx for idx in range(len(key_points_inds_orbits)) if idx not in point_orbits_in_path]
13511347

13521348
for ind in unconnected:
13531349
connect = False

src/pymatgen/symmetry/maggroups.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,15 @@ def _parse_lattice(b):
237237
return None
238238
raw_lattice = [b[i : i + 4] for i in range(0, len(b), 4)]
239239

240-
lattice = []
241-
242-
for r in raw_lattice:
243-
lattice.append(
244-
{
245-
"vector": [r[0] / r[3], r[1] / r[3], r[2] / r[3]],
246-
"str": f"({Fraction(r[0] / r[3]).limit_denominator()},"
247-
f"{Fraction(r[1] / r[3]).limit_denominator()},"
248-
f"{Fraction(r[2] / r[3]).limit_denominator()})+",
249-
}
250-
)
251-
252-
return lattice
240+
return [
241+
{
242+
"vector": [r[0] / r[3], r[1] / r[3], r[2] / r[3]],
243+
"str": f"({Fraction(r[0] / r[3]).limit_denominator()},"
244+
f"{Fraction(r[1] / r[3]).limit_denominator()},"
245+
f"{Fraction(r[2] / r[3]).limit_denominator()})+",
246+
}
247+
for r in raw_lattice
248+
]
253249

254250
def _parse_transformation(b):
255251
"""Parse compact binary representation into transformation between OG and BNS settings."""
@@ -559,9 +555,7 @@ def _write_all_magnetic_space_groups_to_file(filename):
559555
"http://stokes.byu.edu/iso/magnetic_data.txt\n"
560556
"Used with kind permission from Professor Branton Campbell, BYU\n\n"
561557
)
562-
all_msgs = []
563-
for i in range(1, 1652):
564-
all_msgs.append(MagneticSpaceGroup(i))
558+
all_msgs = list(map(MagneticSpaceGroup, range(1, 1652)))
565559
for msg in all_msgs:
566560
out += f"\n{msg.data_str()}\n\n--------\n"
567561
with open(filename, mode="w") as file:

src/pymatgen/symmetry/structure.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ def __str__(self) -> str:
118118
row = [str(idx), site.species_string]
119119
row.extend([f"{j:>10.6f}" for j in site.frac_coords])
120120
row.append(self.wyckoff_symbols[idx])
121-
for key in keys:
122-
row.append(props[key][idx])
121+
row += [props[key][idx] for key in keys]
123122
data.append(row)
124123
outs.append(tabulate(data, headers=["#", "SP", "a", "b", "c", "Wyckoff", *keys]))
125124
return "\n".join(outs)

tests/analysis/test_local_env.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,6 @@ def test_weighted_cn(self):
12021202

12031203
def test_weighted_cn_no_oxid(self):
12041204
cnn = CrystalNN(weighted_cn=True)
1205-
cn_array = []
12061205
# fmt: off
12071206
expected_array = [
12081207
5.8962, 5.8996, 5.8962, 5.8996, 5.7195, 5.7195, 5.7202, 5.7194, 4.0012, 4.0012,
@@ -1211,8 +1210,7 @@ def test_weighted_cn_no_oxid(self):
12111210
]
12121211
# fmt: on
12131212
struct = self.lifepo4.copy().remove_oxidation_states()
1214-
for idx in range(len(struct)):
1215-
cn_array.append(cnn.get_cn(struct, idx, use_weights=True))
1213+
cn_array = [cnn.get_cn(struct, idx, use_weights=True) for idx in range(len(struct))]
12161214

12171215
assert_allclose(expected_array, cn_array, 2)
12181216

0 commit comments

Comments
 (0)