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

Address various deprecation warnings in pytest output #788

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Write the date in place of the "Unreleased" in the case a new version is release
### Fixed

- Adapt to change in dask public API in dask 2024.9.0.
- Address miscellaneous deprecations in dependencies.

## v0.1.0b8 (2024-09-06)

Expand Down
2 changes: 1 addition & 1 deletion tiled/_tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def populate_internal(client):
awkward.Array([1, [2, 3]]), key="d", metadata={"color": "red"}, specs=["alpha"]
)
# sparse
coo = sparse.COO(coords=[[2, 5]], data=[1.3, 7.5], shape=(10,))
coo = sparse.COO(coords=numpy.array([[2, 5]]), data=[1.3, 7.5], shape=(10,))
client.write_sparse(key="e", coords=coo.coords, data=coo.data, shape=coo.shape)

# nested
Expand Down
8 changes: 4 additions & 4 deletions tiled/adapters/tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ def read(self, slice: Optional[NDSlice] = ...) -> NDArray[Any]:
return self._seq.asarray()
if isinstance(slice, int):
# e.g. read(slice=0) -- return an entire image
return tifffile.TiffFile(self._seq.files[slice]).asarray()
return tifffile.TiffFile(self._seq[slice]).asarray()
if isinstance(slice, builtins.slice):
# e.g. read(slice=(...)) -- return a slice along the image axis
return tifffile.TiffSequence(self._seq.files[slice]).asarray()
return tifffile.TiffSequence(self._seq[slice]).asarray()
if isinstance(slice, tuple):
if len(slice) == 0:
return self._seq.asarray()
Expand All @@ -255,10 +255,10 @@ def read(self, slice: Optional[NDSlice] = ...) -> NDArray[Any]:
# Could be int or slice (0, slice(...)) or (0,....); the_rest is converted to a list
if isinstance(image_axis, int):
# e.g. read(slice=(0, ....))
arr = tifffile.TiffFile(self._seq.files[image_axis]).asarray()
arr = tifffile.TiffFile(self._seq[image_axis]).asarray()
elif image_axis is Ellipsis:
# Return all images
arr = tifffile.TiffSequence(self._seq.files).asarray()
arr = tifffile.TiffSequence(self._seq).asarray()
the_rest.insert(0, Ellipsis) # Include any leading dimensions
elif isinstance(image_axis, builtins.slice):
arr = self.read(slice=image_axis)
Expand Down
12 changes: 6 additions & 6 deletions tiled/authn_database/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
import hashlib
import uuid as uuid_module
from datetime import datetime

from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.future import select
Expand Down Expand Up @@ -77,7 +77,7 @@ async def purge_expired(db, cls):
"""
Remove expired entries.
"""
now = datetime.utcnow()
now = datetime.datetime.now(datetime.UTC)
num_expired = 0
statement = (
select(cls)
Expand Down Expand Up @@ -146,7 +146,7 @@ async def lookup_valid_session(db, session_id):
return None
if (
session.expiration_time is not None
and session.expiration_time < datetime.utcnow()
and session.expiration_time < datetime.datetime.now(datetime.UTC)
):
await db.delete(session)
await db.commit()
Expand All @@ -171,7 +171,7 @@ async def lookup_valid_pending_session_by_device_code(db, device_code):
return None
if (
pending_session.expiration_time is not None
and pending_session.expiration_time < datetime.utcnow()
and pending_session.expiration_time < datetime.datetime.now(datetime.UTC)
):
await db.delete(pending_session)
await db.commit()
Expand All @@ -189,7 +189,7 @@ async def lookup_valid_pending_session_by_user_code(db, user_code):
return None
if (
pending_session.expiration_time is not None
and pending_session.expiration_time < datetime.utcnow()
and pending_session.expiration_time < datetime.datetime.now(datetime.UTC)
):
await db.delete(pending_session)
await db.commit()
Expand Down Expand Up @@ -228,7 +228,7 @@ async def lookup_valid_api_key(db, secret):
Look up an API key. Ensure that it is valid.
"""

now = datetime.utcnow()
now = datetime.datetime.now(datetime.UTC)
hashed_secret = hashlib.sha256(secret).digest()
api_key = (
await db.execute(
Expand Down
2 changes: 1 addition & 1 deletion tiled/examples/xdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def read_xdi(data_uri, structure=None, metadata=None, specs=None, access_policy=

# TODO validate

df = pd.read_table(file, delim_whitespace=True, names=col_labels)
df = pd.read_table(file, sep=r"\s+", names=col_labels)

return DataFrameAdapter.from_pandas(
df,
Expand Down
2 changes: 1 addition & 1 deletion tiled/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ async def index(
principal=Security(get_current_principal, scopes=[]),
):
return templates.TemplateResponse(
request,
"index.html",
{
"request": request,
# This is used to construct the link to the React UI.
"root_url": get_root_url(request),
# If defined, this adds a Binder link to the page.
Expand Down
12 changes: 7 additions & 5 deletions tiled/server/authentication.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import datetime
import enum
import hashlib
import secrets
import uuid as uuid_module
import warnings
from datetime import datetime, timedelta
from pathlib import Path
from typing import Optional

Expand Down Expand Up @@ -67,7 +67,7 @@
from .utils import API_KEY_COOKIE_NAME, get_authenticators, get_base_url

ALGORITHM = "HS256"
UNIT_SECOND = timedelta(seconds=1)
UNIT_SECOND = datetime.timedelta(seconds=1)

# Max API keys and Sessions allowed to Principal.
# This is here for at least two reasons:
Expand All @@ -77,13 +77,13 @@
API_KEY_LIMIT = 100
SESSION_LIMIT = 200

DEVICE_CODE_MAX_AGE = timedelta(minutes=15)
DEVICE_CODE_MAX_AGE = datetime.timedelta(minutes=15)
DEVICE_CODE_POLLING_INTERVAL = 5 # seconds


def utcnow():
"UTC now with second resolution"
return datetime.utcnow().replace(microsecond=0)
return datetime.datetime.now(datetime.UTC).replace(microsecond=0)


class Mode(enum.Enum):
Expand Down Expand Up @@ -759,7 +759,9 @@ async def generate_apikey(db, principal, apikey_params, request):
),
)
if apikey_params.expires_in is not None:
expiration_time = utcnow() + timedelta(seconds=apikey_params.expires_in)
expiration_time = utcnow() + datetime.timedelta(
seconds=apikey_params.expires_in
)
else:
expiration_time = None
# The standard 32 byes of entropy,
Expand Down
6 changes: 4 additions & 2 deletions tiled/server/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import collections.abc
import dataclasses
import datetime
import itertools
import math
import operator
Expand All @@ -8,7 +9,6 @@
import types
import uuid
from collections import defaultdict
from datetime import datetime, timedelta
from hashlib import md5
from typing import Any

Expand Down Expand Up @@ -225,7 +225,9 @@ async def construct_entries_response(
keys = tree.keys()[offset : offset + limit] # noqa: E203
items = [(key, None) for key in keys]
# This value will not leak out. It just used to seed comparisons.
metadata_stale_at = datetime.utcnow() + timedelta(days=1_000_000)
metadata_stale_at = datetime.datetime.now(datetime.UTC) + datetime.timedelta(
days=1_000_000
)
must_revalidate = getattr(tree, "must_revalidate", True)
for key, entry in items:
resource = await construct_resource(
Expand Down
4 changes: 2 additions & 2 deletions tiled/server/router.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import dataclasses
import datetime
import inspect
import os
import re
import warnings
from datetime import datetime, timedelta
from functools import partial
from pathlib import Path
from typing import Any, List, Optional
Expand Down Expand Up @@ -149,7 +149,7 @@ async def about(
},
meta={"root_path": request.scope.get("root_path") or "" + "/api"},
).model_dump(),
expires=datetime.utcnow() + timedelta(seconds=600),
expires=datetime.datetime.now(datetime.UTC) + datetime.timedelta(seconds=600),
)


Expand Down
Loading