From aac6f057244fb36e71cfd89f7b529634b974db07 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 22 Aug 2023 05:39:16 +0000 Subject: [PATCH 1/8] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.0.284 → v0.0.285](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.284...v0.0.285) - [github.com/asottile/blacken-docs: 1.15.0 → 1.16.0](https://github.com/asottile/blacken-docs/compare/1.15.0...1.16.0) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fe362cb0e..ab4fca9c8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: - id: black-jupyter - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.0.284 + rev: v0.0.285 hooks: - id: ruff args: ["--fix"] @@ -35,7 +35,7 @@ repos: args: ["--write"] # Python inside docs - repo: https://github.com/asottile/blacken-docs - rev: 1.15.0 + rev: 1.16.0 hooks: - id: blacken-docs ci: From ef4e4505780359c675fe48b61fd6a6d3a7a10089 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 22 Aug 2023 05:40:00 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- plugin_example/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin_example/README.md b/plugin_example/README.md index 322756f93..a506a4e88 100644 --- a/plugin_example/README.md +++ b/plugin_example/README.md @@ -6,6 +6,7 @@ pip install . ```py import dpdata + print(dpdata.System(12, fmt="random")) ``` From 45659ad0b192aef0565765134ca5c1ffa1606e53 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 22 Aug 2023 14:54:53 -0400 Subject: [PATCH 3/8] fix E721 Do not compare types, use `isinstance()` --- dpdata/abacus/md.py | 2 +- dpdata/md/rdf.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dpdata/abacus/md.py b/dpdata/abacus/md.py index 55538d0b1..4b8ec0387 100644 --- a/dpdata/abacus/md.py +++ b/dpdata/abacus/md.py @@ -206,7 +206,7 @@ def get_frame(fname): data["energies"] = energy data["forces"] = force data["virials"] = stress - if type(data["virials"]) != np.ndarray: + if not isinstance(data["virials"], np.ndarray): del data["virials"] data["orig"] = np.zeros(3) diff --git a/dpdata/md/rdf.py b/dpdata/md/rdf.py index d5409a0ce..de8f1c746 100644 --- a/dpdata/md/rdf.py +++ b/dpdata/md/rdf.py @@ -62,9 +62,9 @@ def _compute_rdf_1frame(box, posis, atype, sel_type=[None, None], max_r=5, nbins sel_type[0] = all_types if sel_type[1] is None: sel_type[1] = all_types - if type(sel_type[0]) is not list: + if not isinstance(sel_type[0], list): sel_type[0] = [sel_type[0]] - if type(sel_type[1]) is not list: + if not isinstance(sel_type[1], list): sel_type[1] = [sel_type[1]] natoms = len(posis) import ase.neighborlist From 37c703a2d4354be616a3ac983c8cbf8ed0ae6275 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 22 Aug 2023 15:29:59 -0400 Subject: [PATCH 4/8] raise error in the subclass --- dpdata/system.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dpdata/system.py b/dpdata/system.py index cf03aa617..920871326 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -686,10 +686,6 @@ def replicate(self, ncopy): return tmp def replace(self, initial_atom_type, end_atom_type, replace_num): - if type(self) is not dpdata.System: - raise RuntimeError( - "Must use method replace() of the instance of class dpdata.System" - ) if not isinstance(replace_num, int): raise ValueError(f"replace_num must be a integer. Now is {replace_num}") if replace_num <= 0: @@ -1180,6 +1176,11 @@ def remove_outlier(self, threshold: float = 8.0) -> "LabeledSystem": idx = np.abs(energies - np.mean(energies)) / std < threshold return self.sub_system(idx) + def replace(self, initial_atom_type, end_atom_type, replace_num): + raise RuntimeError( + "Must use method replace() of the instance of class dpdata.System" + ) + class MultiSystems: """A set containing several systems.""" From 4b3f2419f5577ef1d9ed3ee3cf896518f6bbda9e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 22 Aug 2023 19:30:11 +0000 Subject: [PATCH 5/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpdata/system.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dpdata/system.py b/dpdata/system.py index 920871326..dfa607680 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -1178,8 +1178,8 @@ def remove_outlier(self, threshold: float = 8.0) -> "LabeledSystem": def replace(self, initial_atom_type, end_atom_type, replace_num): raise RuntimeError( - "Must use method replace() of the instance of class dpdata.System" - ) + "Must use method replace() of the instance of class dpdata.System" + ) class MultiSystems: From 122b98eddf16438523b7650014c1cfde83ea6d20 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 22 Aug 2023 15:32:48 -0400 Subject: [PATCH 6/8] Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks" This reverts commit 4b3f2419f5577ef1d9ed3ee3cf896518f6bbda9e. --- dpdata/system.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dpdata/system.py b/dpdata/system.py index dfa607680..920871326 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -1178,8 +1178,8 @@ def remove_outlier(self, threshold: float = 8.0) -> "LabeledSystem": def replace(self, initial_atom_type, end_atom_type, replace_num): raise RuntimeError( - "Must use method replace() of the instance of class dpdata.System" - ) + "Must use method replace() of the instance of class dpdata.System" + ) class MultiSystems: From 515ef3529cc1fa7e53b82dc0d2cf2f11d3669d11 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 22 Aug 2023 15:32:49 -0400 Subject: [PATCH 7/8] Revert "raise error in the subclass" This reverts commit 37c703a2d4354be616a3ac983c8cbf8ed0ae6275. --- dpdata/system.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/dpdata/system.py b/dpdata/system.py index 920871326..cf03aa617 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -686,6 +686,10 @@ def replicate(self, ncopy): return tmp def replace(self, initial_atom_type, end_atom_type, replace_num): + if type(self) is not dpdata.System: + raise RuntimeError( + "Must use method replace() of the instance of class dpdata.System" + ) if not isinstance(replace_num, int): raise ValueError(f"replace_num must be a integer. Now is {replace_num}") if replace_num <= 0: @@ -1176,11 +1180,6 @@ def remove_outlier(self, threshold: float = 8.0) -> "LabeledSystem": idx = np.abs(energies - np.mean(energies)) / std < threshold return self.sub_system(idx) - def replace(self, initial_atom_type, end_atom_type, replace_num): - raise RuntimeError( - "Must use method replace() of the instance of class dpdata.System" - ) - class MultiSystems: """A set containing several systems.""" From 411c0882ece0f3eea8f11caf912e0713a9f496a7 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 22 Aug 2023 15:33:19 -0400 Subject: [PATCH 8/8] fix E721 Do not compare types, use isinstance() --- dpdata/system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpdata/system.py b/dpdata/system.py index cf03aa617..daf0c8858 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -509,7 +509,7 @@ def check_type_map(self, type_map): self.sort_atom_names(type_map=type_map) def apply_type_map(self, type_map): - if type_map is not None and type(type_map) is list: + if type_map is not None and isinstance(type_map, list): self.check_type_map(type_map) else: raise RuntimeError("invalid type map, cannot be applied")