Skip to content

Commit

Permalink
Remove deprecated utcnow and utcfromtimestamp (#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthomas23 authored Jul 21, 2023
1 parent 22ede85 commit e64f0a1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
6 changes: 4 additions & 2 deletions fsspec/implementations/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,13 @@ def touch(self, path, truncate=True, **kwargs):

def created(self, path):
info = self.info(path=path)
return datetime.datetime.utcfromtimestamp(info["created"])
return datetime.datetime.fromtimestamp(
info["created"], tz=datetime.timezone.utc
)

def modified(self, path):
info = self.info(path=path)
return datetime.datetime.utcfromtimestamp(info["mtime"])
return datetime.datetime.fromtimestamp(info["mtime"], tz=datetime.timezone.utc)

@classmethod
def _parent(cls, path):
Expand Down
8 changes: 4 additions & 4 deletions fsspec/implementations/memory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import, annotations, division, print_function

import logging
from datetime import datetime
from datetime import datetime, timezone
from errno import ENOTEMPTY
from io import BytesIO
from typing import Any, ClassVar
Expand Down Expand Up @@ -268,8 +268,8 @@ def __init__(self, fs=None, path=None, data=None):
logger.debug("open file %s", path)
self.fs = fs
self.path = path
self.created = datetime.utcnow()
self.modified = datetime.utcnow()
self.created = datetime.now(tz=timezone.utc)
self.modified = datetime.now(tz=timezone.utc)
if data:
super().__init__(data)
self.seek(0)
Expand All @@ -289,4 +289,4 @@ def discard(self):

def commit(self):
self.fs.store[self.path] = self
self.modified = datetime.utcnow()
self.modified = datetime.now(tz=timezone.utc)
8 changes: 6 additions & 2 deletions fsspec/implementations/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ def _decode_stat(stat, parent_path=None):
"type": t,
"uid": stat.st_uid,
"gid": stat.st_gid,
"time": datetime.datetime.utcfromtimestamp(stat.st_atime),
"mtime": datetime.datetime.utcfromtimestamp(stat.st_mtime),
"time": datetime.datetime.fromtimestamp(
stat.st_atime, tz=datetime.timezone.utc
),
"mtime": datetime.datetime.fromtimestamp(
stat.st_mtime, tz=datetime.timezone.utc
),
}
if parent_path:
out["name"] = "/".join([parent_path.rstrip("/"), stat.filename])
Expand Down
4 changes: 2 additions & 2 deletions fsspec/implementations/smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ def created(self, path):
"""Return the created timestamp of a file as a datetime.datetime"""
wpath = _as_unc_path(self.host, path)
stats = smbclient.stat(wpath, port=self.port)
return datetime.datetime.utcfromtimestamp(stats.st_ctime)
return datetime.datetime.fromtimestamp(stats.st_ctime, tz=datetime.timezone.utc)

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

def ls(self, path, detail=True, **kwargs):
unc = _as_unc_path(self.host, path)
Expand Down
6 changes: 4 additions & 2 deletions fsspec/implementations/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ def test_modified(fs: AbstractFileSystem, temp_file):
try:
fs.touch(temp_file)
# created = fs.created(path=temp_file)
created = datetime.datetime.utcnow() # pyarrow only have modified
created = datetime.datetime.now(
tz=datetime.timezone.utc
) # pyarrow only have modified
time.sleep(0.05)
fs.touch(temp_file)
modified = fs.modified(path=temp_file).replace(tzinfo=None)
modified = fs.modified(path=temp_file)
assert isinstance(modified, datetime.datetime)
assert modified > created
finally:
Expand Down

0 comments on commit e64f0a1

Please sign in to comment.