Skip to content

Commit 0f8b8fd

Browse files
committed
fix ruff DTZ003 (closes #3791)
1 parent 41e6d99 commit 0f8b8fd

File tree

8 files changed

+21
-23
lines changed

8 files changed

+21
-23
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ ignore = [
205205
"D105", # Missing docstring in magic method
206206
"D205", # 1 blank line required between summary line and description
207207
"D212", # Multi-line docstring summary should start at the first line
208-
"DTZ003", # TODO: fix this (issue #3791)
209208
"FBT001", # Boolean-typed positional argument in function definition
210209
"FBT002", # Boolean default positional argument in function
211210
"PD901", # pandas-df-variable-name

src/pymatgen/alchemy/materials.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
from __future__ import annotations
77

8-
import datetime
98
import json
109
import re
10+
from datetime import datetime, timezone
1111
from typing import TYPE_CHECKING
1212
from warnings import warn
1313

@@ -302,7 +302,7 @@ def from_cif_str(
302302
source = "uploaded cif"
303303
source_info = {
304304
"source": source,
305-
"datetime": str(datetime.datetime.now(tz=datetime.timezone.utc)),
305+
"datetime": str(datetime.now(tz=timezone.utc)),
306306
"original_file": raw_str,
307307
"cif_data": cif_dict[cif_keys[0]],
308308
}
@@ -330,7 +330,7 @@ def from_poscar_str(
330330
struct = poscar.structure
331331
source_info = {
332332
"source": "POSCAR",
333-
"datetime": str(datetime.datetime.now(tz=datetime.timezone.utc)),
333+
"datetime": str(datetime.now(tz=timezone.utc)),
334334
"original_file": raw_str,
335335
}
336336
return cls(struct, transformations, history=[source_info])
@@ -341,7 +341,7 @@ def as_dict(self) -> dict[str, Any]:
341341
dct["@module"] = type(self).__module__
342342
dct["@class"] = type(self).__name__
343343
dct["history"] = jsanitize(self.history)
344-
dct["last_modified"] = str(datetime.datetime.now(datetime.timezone.utc))
344+
dct["last_modified"] = str(datetime.now(timezone.utc))
345345
dct["other_parameters"] = jsanitize(self.other_parameters)
346346
return dct
347347

src/pymatgen/analysis/ewald.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import bisect
66
import math
77
from copy import copy, deepcopy
8-
from datetime import datetime
8+
from datetime import datetime, timezone
99
from typing import TYPE_CHECKING
1010
from warnings import warn
1111

@@ -535,7 +535,7 @@ def __init__(self, matrix, m_list, num_to_return=1, algo=ALGO_FAST):
535535
# sets this to true it breaks the recursion and stops the search.
536536
self._finished = False
537537

538-
self._start_time = datetime.utcnow()
538+
self._start_time = datetime.now(tz=timezone.utc)
539539

540540
self.minimize_matrix()
541541

@@ -605,7 +605,7 @@ def best_case(self, matrix, m_list, indices_left):
605605
interaction_correction = np.sum(step3)
606606

607607
if self._algo == self.ALGO_TIME_LIMIT:
608-
elapsed_time = datetime.utcnow() - self._start_time
608+
elapsed_time = datetime.now(tz=timezone.utc) - self._start_time
609609
speedup_parameter = elapsed_time.total_seconds() / 1800
610610
avg_int = np.sum(interaction_matrix, axis=None)
611611
avg_frac = np.mean(np.outer(1 - fractions, 1 - fractions))

src/pymatgen/entries/entry_tools.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
import collections
88
import csv
9-
import datetime
109
import itertools
1110
import json
1211
import logging
1312
import multiprocessing as mp
1413
import re
1514
from collections import defaultdict
15+
from datetime import datetime, timezone
1616
from typing import TYPE_CHECKING
1717

1818
from monty.json import MontyDecoder, MontyEncoder, MSONable
@@ -112,7 +112,7 @@ def group_entries_by_structure(
112112
"""
113113
if comparator is None:
114114
comparator = SpeciesComparator()
115-
start = datetime.datetime.now(tz=datetime.timezone.utc)
115+
start = datetime.now(tz=timezone.utc)
116116
logger.info(f"Started at {start}")
117117
entries_host = [(entry, _get_host(entry.structure, species_to_remove)) for entry in entries]
118118
if ncpus:
@@ -161,8 +161,8 @@ def group_entries_by_structure(
161161
entry_groups = []
162162
for g in groups:
163163
entry_groups.append(json.loads(g, cls=MontyDecoder))
164-
logging.info(f"Finished at {datetime.datetime.now(tz=datetime.timezone.utc)}")
165-
logging.info(f"Took {datetime.datetime.now(tz=datetime.timezone.utc) - start}")
164+
logging.info(f"Finished at {datetime.now(tz=timezone.utc)}")
165+
logging.info(f"Took {datetime.now(tz=timezone.utc) - start}")
166166
return entry_groups
167167

168168

src/pymatgen/io/res.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
from __future__ import annotations
1212

13-
import datetime
1413
import re
1514
from dataclasses import dataclass
15+
from datetime import date, datetime, timezone
1616
from typing import TYPE_CHECKING
1717

1818
from monty.io import zopen
@@ -24,7 +24,6 @@
2424

2525
if TYPE_CHECKING:
2626
from collections.abc import Iterator
27-
from datetime import date
2827
from pathlib import Path
2928
from typing import Any, Callable, Literal
3029

@@ -421,9 +420,9 @@ def _parse_date(cls, string: str) -> date:
421420
raise ResParseError(f"Could not parse the date from {string=}.")
422421

423422
day, month, year, *_ = match.groups()
424-
month_num = datetime.datetime.strptime(month, "%b").replace(tzinfo=datetime.timezone.utc).month
423+
month_num = datetime.strptime(month, "%b").replace(tzinfo=timezone.utc).month
425424

426-
return datetime.date(int(year), month_num, int(day))
425+
return date(int(year), month_num, int(day))
427426

428427
def _raise_or_none(self, err: ResParseError) -> None:
429428
if self.parse_rems != "strict":

src/pymatgen/io/vasp/outputs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import datetime
65
import itertools
76
import logging
87
import math
@@ -13,6 +12,7 @@
1312
from collections import defaultdict
1413
from collections.abc import Iterable
1514
from dataclasses import dataclass
15+
from datetime import datetime, timezone
1616
from glob import glob
1717
from io import StringIO
1818
from pathlib import Path
@@ -845,7 +845,7 @@ def get_computed_entry(
845845
ComputedStructureEntry/ComputedEntry
846846
"""
847847
if entry_id is None:
848-
entry_id = f"vasprun-{datetime.datetime.now(tz=datetime.timezone.utc)}"
848+
entry_id = f"vasprun-{datetime.now(tz=timezone.utc)}"
849849
param_names = {
850850
"is_hubbard",
851851
"hubbards",

src/pymatgen/util/provenance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from __future__ import annotations
44

5-
import datetime
65
import json
76
import re
87
import sys
8+
from datetime import datetime, timezone
99
from io import StringIO
1010
from typing import TYPE_CHECKING, NamedTuple
1111

@@ -256,7 +256,7 @@ def __init__(
256256
if not all(sys.getsizeof(h) < MAX_HNODE_SIZE for h in history):
257257
raise ValueError(f"One or more history nodes exceeds the maximum size limit of {MAX_HNODE_SIZE} bytes")
258258

259-
self.created_at = created_at or datetime.datetime.utcnow()
259+
self.created_at = created_at or datetime.now(tz=timezone.utc)
260260

261261
def as_dict(self):
262262
"""Get MSONable dict."""

tasks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
from __future__ import annotations
1111

12-
import datetime
1312
import json
1413
import os
1514
import re
1615
import subprocess
1716
import webbrowser
17+
from datetime import datetime, timezone
1818
from typing import TYPE_CHECKING
1919

2020
import requests
@@ -150,7 +150,7 @@ def update_changelog(ctx: Context, version: str | None = None, dry_run: bool = F
150150
dry_run (bool, optional): If True, the function will only print the changes without
151151
updating the actual change log file. Defaults to False.
152152
"""
153-
version = version or f"{datetime.datetime.now(tz=datetime.timezone.utc):%Y.%-m.%-d}"
153+
version = version or f"{datetime.now(tz=timezone.utc):%Y.%-m.%-d}"
154154
output = subprocess.check_output(["git", "log", "--pretty=format:%s", f"v{__version__}..HEAD"])
155155
lines = []
156156
ignored_commits = []
@@ -197,7 +197,7 @@ def release(ctx: Context, version: str | None = None, nodoc: bool = False) -> No
197197
version (str, optional): The version to release.
198198
nodoc (bool, optional): Whether to skip documentation generation.
199199
"""
200-
version = version or f"{datetime.datetime.now(tz=datetime.timezone.utc):%Y.%-m.%-d}"
200+
version = version or f"{datetime.now(tz=timezone.utc):%Y.%-m.%-d}"
201201
ctx.run("rm -r dist build pymatgen.egg-info", warn=True)
202202
set_ver(ctx, version)
203203
if not nodoc:

0 commit comments

Comments
 (0)