Skip to content

Commit e64f0a1

Browse files
authored
Remove deprecated utcnow and utcfromtimestamp (#1314)
1 parent 22ede85 commit e64f0a1

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

fsspec/implementations/local.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,13 @@ def touch(self, path, truncate=True, **kwargs):
196196

197197
def created(self, path):
198198
info = self.info(path=path)
199-
return datetime.datetime.utcfromtimestamp(info["created"])
199+
return datetime.datetime.fromtimestamp(
200+
info["created"], tz=datetime.timezone.utc
201+
)
200202

201203
def modified(self, path):
202204
info = self.info(path=path)
203-
return datetime.datetime.utcfromtimestamp(info["mtime"])
205+
return datetime.datetime.fromtimestamp(info["mtime"], tz=datetime.timezone.utc)
204206

205207
@classmethod
206208
def _parent(cls, path):

fsspec/implementations/memory.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import absolute_import, annotations, division, print_function
22

33
import logging
4-
from datetime import datetime
4+
from datetime import datetime, timezone
55
from errno import ENOTEMPTY
66
from io import BytesIO
77
from typing import Any, ClassVar
@@ -268,8 +268,8 @@ def __init__(self, fs=None, path=None, data=None):
268268
logger.debug("open file %s", path)
269269
self.fs = fs
270270
self.path = path
271-
self.created = datetime.utcnow()
272-
self.modified = datetime.utcnow()
271+
self.created = datetime.now(tz=timezone.utc)
272+
self.modified = datetime.now(tz=timezone.utc)
273273
if data:
274274
super().__init__(data)
275275
self.seek(0)
@@ -289,4 +289,4 @@ def discard(self):
289289

290290
def commit(self):
291291
self.fs.store[self.path] = self
292-
self.modified = datetime.utcnow()
292+
self.modified = datetime.now(tz=timezone.utc)

fsspec/implementations/sftp.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ def _decode_stat(stat, parent_path=None):
110110
"type": t,
111111
"uid": stat.st_uid,
112112
"gid": stat.st_gid,
113-
"time": datetime.datetime.utcfromtimestamp(stat.st_atime),
114-
"mtime": datetime.datetime.utcfromtimestamp(stat.st_mtime),
113+
"time": datetime.datetime.fromtimestamp(
114+
stat.st_atime, tz=datetime.timezone.utc
115+
),
116+
"mtime": datetime.datetime.fromtimestamp(
117+
stat.st_mtime, tz=datetime.timezone.utc
118+
),
115119
}
116120
if parent_path:
117121
out["name"] = "/".join([parent_path.rstrip("/"), stat.filename])

fsspec/implementations/smb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ def created(self, path):
177177
"""Return the created timestamp of a file as a datetime.datetime"""
178178
wpath = _as_unc_path(self.host, path)
179179
stats = smbclient.stat(wpath, port=self.port)
180-
return datetime.datetime.utcfromtimestamp(stats.st_ctime)
180+
return datetime.datetime.fromtimestamp(stats.st_ctime, tz=datetime.timezone.utc)
181181

182182
def modified(self, path):
183183
"""Return the modified timestamp of a file as a datetime.datetime"""
184184
wpath = _as_unc_path(self.host, path)
185185
stats = smbclient.stat(wpath, port=self.port)
186-
return datetime.datetime.utcfromtimestamp(stats.st_mtime)
186+
return datetime.datetime.fromtimestamp(stats.st_mtime, tz=datetime.timezone.utc)
187187

188188
def ls(self, path, detail=True, **kwargs):
189189
unc = _as_unc_path(self.host, path)

fsspec/implementations/tests/test_common.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ def test_modified(fs: AbstractFileSystem, temp_file):
2323
try:
2424
fs.touch(temp_file)
2525
# created = fs.created(path=temp_file)
26-
created = datetime.datetime.utcnow() # pyarrow only have modified
26+
created = datetime.datetime.now(
27+
tz=datetime.timezone.utc
28+
) # pyarrow only have modified
2729
time.sleep(0.05)
2830
fs.touch(temp_file)
29-
modified = fs.modified(path=temp_file).replace(tzinfo=None)
31+
modified = fs.modified(path=temp_file)
3032
assert isinstance(modified, datetime.datetime)
3133
assert modified > created
3234
finally:

0 commit comments

Comments
 (0)