Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fixable ruff rules #4015

Merged
merged 33 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
317ebd9
fix RUF017
DanielYang59 Aug 25, 2024
dbb52e6
fix B018: useless expressions
DanielYang59 Aug 25, 2024
7d03f14
NEED confirm: fix TRY004 type error
DanielYang59 Aug 25, 2024
53f89f0
fix PGH003: bare # type: ignore
DanielYang59 Aug 25, 2024
be99826
fix FBT003 boolean-positional-value-in-call
DanielYang59 Aug 25, 2024
79c0c87
fix PYI024 collections-named-tuple
DanielYang59 Aug 25, 2024
9fd02e0
relocate io.aims test file and rename test dir
DanielYang59 Aug 25, 2024
ee394be
NEED CONFIRM: relocate io.aims test helper functions
DanielYang59 Aug 25, 2024
381571e
add __init__.py
DanielYang59 Aug 25, 2024
f1bba42
try to fix helper function path
DanielYang59 Aug 25, 2024
8057ff6
pre-commit auto-fixes
pre-commit-ci[bot] Aug 25, 2024
e0af132
clean up pyproject.toml
DanielYang59 Aug 25, 2024
27550eb
relocate type check import
DanielYang59 Aug 25, 2024
cf24f12
use relative import, TODO how to use abs import in this case?
DanielYang59 Aug 25, 2024
101c558
fix NPY201
DanielYang59 Aug 25, 2024
735cb62
turn of paradox box of S101
DanielYang59 Aug 25, 2024
2751e64
Revert "turn of paradox box of S101"
DanielYang59 Aug 26, 2024
b466559
tweak type and docstring
DanielYang59 Aug 26, 2024
7b5cc69
fix PD011, got a lot false pos in cp2k keywords
DanielYang59 Aug 26, 2024
9cfd546
ignore PD011 as too many false pos https://github.com/astral-sh/ruff/…
DanielYang59 Aug 26, 2024
993b92c
one missing pd011
DanielYang59 Aug 26, 2024
6da15fa
fix usage of pytest raise message PT011
DanielYang59 Aug 27, 2024
b2685a5
fix B009 get attribute
DanielYang59 Aug 27, 2024
09f7692
fix B018, attr test
DanielYang59 Aug 27, 2024
e5938f6
use np array to avoid RUF005 error
DanielYang59 Aug 27, 2024
01be529
fix RUF005 with np array
DanielYang59 Aug 27, 2024
6b42af3
fix typo in hasattr use
DanielYang59 Aug 27, 2024
ae52433
NEED CONFIRM: turn on SSL certificate check
DanielYang59 Aug 27, 2024
8fdd1c5
replace http with https, there're many other cases might need test an…
DanielYang59 Aug 27, 2024
6de9a21
Revert "replace http with https, there're many other cases might need…
DanielYang59 Aug 27, 2024
81b4f76
Move to another PR, Revert "NEED CONFIRM: turn on SSL certificate check"
DanielYang59 Aug 27, 2024
ef9a46c
rename _SpinMode to SpinModeTuple
DanielYang59 Aug 28, 2024
8f5f519
use list comprehension over function tool to flat list of lists
DanielYang59 Aug 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dev_scripts/update_pt_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

from __future__ import annotations

import functools
import json
import operator
import re
from collections import defaultdict
from itertools import product
Expand Down Expand Up @@ -217,7 +219,7 @@ def gen_iupac_ordering():
([17], range(6, 1, -1)),
] # At -> F

order = sum((list(product(x, y)) for x, y in order), []) # noqa: RUF017
order = functools.reduce(operator.iadd, (list(product(x, y)) for x, y in order), [])
iupac_ordering_dict = dict(
zip([Element.from_row_and_group(row, group) for group, row in order], range(len(order)), strict=True)
)
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ ignore = [
"PLR0913", # Too many arguments
"PLR0915", # Too many statements
"PLR1702", # Too many nested blocks
"PLR2004", # Magic-value-comparison TODO fix these
"PLR2004", # Magic-value-comparison TODO: fix these
"PLW2901", # Outer for loop variable overwritten by inner assignment target
"PT013", # Incorrect import of pytest
"S101", # Use of "assert"
"PT013", # Incorrect import of pytest # TODO: fix these
"S101", # Use of "assert" TODO: fix these
"S110", # Log for try-except-pass
"S112", # Log for try-except-continue
"S311", # Use random module for cryptographic purposes
Expand Down
4 changes: 3 additions & 1 deletion src/pymatgen/analysis/adsorption.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

from __future__ import annotations

import functools
import itertools
import operator
import os
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -300,7 +302,7 @@ def find_adsorption_sites(
sites = [site + distance * np.asarray(self.mvec) for site in sites]

ads_sites[key] = sites
ads_sites["all"] = sum(ads_sites.values(), []) # noqa: RUF017
ads_sites["all"] = functools.reduce(operator.iadd, ads_sites.values(), [])
DanielYang59 marked this conversation as resolved.
Show resolved Hide resolved
return ads_sites

def symm_reduce(self, coords_set, threshold=1e-6):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@


def _is_ox(structure):
for elem in structure.composition:
try:
elem.oxi_state # noqa: B018
except AttributeError:
return False
return True
return all(hasattr(elem, "oxi_state") for elem in structure.composition)


class RLSVolumePredictor:
Expand Down
6 changes: 3 additions & 3 deletions src/pymatgen/cli/pmg.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@ def main():
args = parser.parse_args()

try:
args.func # noqa: B018
except AttributeError:
_ = args.func
except AttributeError as exc:
parser.print_help()
raise SystemExit("Please specify a command.")
raise SystemExit("Please specify a command.") from exc
return args.func(args)


Expand Down
4 changes: 2 additions & 2 deletions src/pymatgen/electronic_structure/boltztrap2.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,8 @@ def compute_properties_doping(self, doping, temp_r=None) -> None:
self.nelect + dop_car,
temp,
self.dosweight,
True, # noqa: FBT003
False, # noqa: FBT003
refine=True,
try_center=False,
)

N, L0, L1, L2, Lm11 = BL.fermiintegrals(
Expand Down
4 changes: 2 additions & 2 deletions src/pymatgen/electronic_structure/dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,8 +1337,8 @@ def get_dos_fp_similarity(
vec1 = np.array([pt[col] for pt in fp1_dict.values()]).flatten()
vec2 = np.array([pt[col] for pt in fp2_dict.values()]).flatten()
else:
vec1 = fp1_dict[fp1[2][pt]][col] # type: ignore # noqa:PGH003
vec2 = fp2_dict[fp2[2][pt]][col] # type: ignore # noqa:PGH003
vec1 = fp1_dict[fp1[2][pt]][col]
vec2 = fp2_dict[fp2[2][pt]][col]

if not normalize and metric == "tanimoto":
rescale = np.linalg.norm(vec1) ** 2 + np.linalg.norm(vec2) ** 2 - np.dot(vec1, vec2)
Expand Down
12 changes: 9 additions & 3 deletions src/pymatgen/io/abinit/abiobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from __future__ import annotations

import abc
from collections import namedtuple
from collections.abc import Iterable
from enum import Enum, unique
from pprint import pformat
from typing import TYPE_CHECKING, cast
from typing import TYPE_CHECKING, NamedTuple, cast

import numpy as np
from monty.collections import AttrDict
Expand Down Expand Up @@ -339,7 +338,14 @@ class DefaultVariable:
DEFAULT = DefaultVariable()


class SpinMode(namedtuple("SpinMode", "mode nsppol nspinor nspden"), AbivarAble, MSONable): # noqa: PYI024
class _SpinMode(NamedTuple):
DanielYang59 marked this conversation as resolved.
Show resolved Hide resolved
mode: str
nsppol: int
nspinor: int
nspden: int


class SpinMode(_SpinMode, AbivarAble, MSONable):
"""
Different configurations of the electron density as implemented in abinit:
One can use as_spinmode to construct the object via SpinMode.as_spinmode
Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/io/aims/sets/bs.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_parameter_updates(
dict: The updated for the parameters for the output section of FHI-aims
"""
if isinstance(structure, Molecule):
raise ValueError("BandStructures can not be made for non-periodic systems") # noqa: TRY004
Copy link
Contributor Author

@DanielYang59 DanielYang59 Aug 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ValueError changed to TypeError, tests seem to pass.

raise TypeError("BandStructures can not be made for non-periodic systems")

updated_outputs = prev_parameters.get("output", [])
updated_outputs += prepare_band_input(structure, self.k_point_density)
Expand Down
4 changes: 2 additions & 2 deletions src/pymatgen/phonon/dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ def get_dos_fp_similarity(
vec1 = np.array([pt[col] for pt in fp1_dict.values()]).flatten()
vec2 = np.array([pt[col] for pt in fp2_dict.values()]).flatten()
else:
vec1 = fp1_dict[fp1[2][pt]][col] # type: ignore # noqa:PGH003
vec2 = fp2_dict[fp2[2][pt]][col] # type: ignore # noqa:PGH003
vec1 = fp1_dict[fp1[2][pt]][col] # type: ignore[index]
vec2 = fp2_dict[fp2[2][pt]][col] # type: ignore[index]

if not normalize and metric == "tanimoto":
rescale = np.linalg.norm(vec1) ** 2 + np.linalg.norm(vec2) ** 2 - np.dot(vec1, vec2)
Expand Down
154 changes: 0 additions & 154 deletions src/pymatgen/util/testing/aims.py

This file was deleted.

Empty file added tests/io/aims/__init__.py
Empty file.
Loading
Loading