Skip to content

Commit

Permalink
fix: fix datetime deprecation with timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
MilagrosMarin committed Oct 29, 2024
1 parent 31b7fb3 commit cc7e759
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions aeon/dj_pipeline/analysis/block_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import itertools
import json
from collections import defaultdict
from datetime import UTC, datetime
from datetime import datetime, timezone

import datajoint as dj
import numpy as np
Expand Down Expand Up @@ -268,7 +268,7 @@ def make(self, key):
# log a note and pick the first rate to move forward
AnalysisNote.insert1(
{
"note_timestamp": datetime.now(UTC),
"note_timestamp": datetime.now(timezone.utc),
"note_type": "Multiple patch rates",
"note": (
f"Found multiple patch rates for block {key} "
Expand Down
4 changes: 2 additions & 2 deletions aeon/dj_pipeline/analysis/visit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Module for visit-related tables in the analysis schema."""

import datetime
from datetime import datetime, timezone
from collections import deque

import datajoint as dj
Expand Down Expand Up @@ -143,7 +143,7 @@ def ingest_environment_visits(experiment_names: list | None = None):
.fetch("last_visit")
)
start = min(subjects_last_visits) if len(subjects_last_visits) else "1900-01-01"
end = datetime.datetime.now() if start else "2200-01-01"
end = datetime.now(timezone.utc) if start else "2200-01-01"

enter_exit_query = (
acquisition.SubjectEnterExit.Time * acquisition.EventType
Expand Down
18 changes: 9 additions & 9 deletions aeon/dj_pipeline/subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import os
import time
from datetime import UTC, datetime, timedelta
from datetime import datetime, timedelta, timezone

import datajoint as dj
import requests
Expand Down Expand Up @@ -195,7 +195,7 @@ def get_reference_weight(cls, subject_name):
"procedure_date", order_by="procedure_date DESC", limit=1
)[0]
else:
ref_date = datetime.now(UTC).date()
ref_date = datetime.now(timezone.utc).date()

weight_query = SubjectWeight & subj_key & f"weight_time < '{ref_date}'"
ref_weight = (
Expand All @@ -207,7 +207,7 @@ def get_reference_weight(cls, subject_name):
entry = {
"subject": subject_name,
"reference_weight": ref_weight,
"last_updated_time": datetime.now(UTC),
"last_updated_time": datetime.now(timezone.utc),
}
cls.update1(entry) if cls & {"subject": subject_name} else cls.insert1(entry)

Expand Down Expand Up @@ -250,7 +250,7 @@ class PyratIngestion(dj.Imported):

def _auto_schedule(self):
"""Automatically schedule the next task."""
utc_now = datetime.now(UTC)
utc_now = datetime.now(timezone.utc)

next_task_schedule_time = utc_now + timedelta(hours=self.schedule_interval)
if (
Expand All @@ -265,7 +265,7 @@ def _auto_schedule(self):

def make(self, key):
"""Automatically import or update entries in the Subject table."""
execution_time = datetime.now(UTC)
execution_time = datetime.now(timezone.utc)
new_eartags = []
for responsible_id in lab.User.fetch("responsible_id"):
# 1 - retrieve all animals from this user
Expand Down Expand Up @@ -301,7 +301,7 @@ def make(self, key):
new_entry_count += 1

logger.info(f"Inserting {new_entry_count} new subject(s) from Pyrat")
completion_time = datetime.now(UTC)
completion_time = datetime.now(timezone.utc)
self.insert1(
{
**key,
Expand Down Expand Up @@ -334,7 +334,7 @@ class PyratCommentWeightProcedure(dj.Imported):

def make(self, key):
"""Automatically import or update entries in the PyratCommentWeightProcedure table."""
execution_time = datetime.now(UTC)
execution_time = datetime.now(timezone.utc)
logger.info("Extracting weights/comments/procedures")

eartag_or_id = key["subject"]
Expand Down Expand Up @@ -377,7 +377,7 @@ def make(self, key):
# compute/update reference weight
SubjectReferenceWeight.get_reference_weight(eartag_or_id)
finally:
completion_time = datetime.now(UTC)
completion_time = datetime.now(timezone.utc)
self.insert1(
{
**key,
Expand All @@ -398,7 +398,7 @@ class CreatePyratIngestionTask(dj.Computed):
def make(self, key):
"""Create one new PyratIngestionTask for every newly added users."""
PyratIngestionTask.insert1(
{"pyrat_task_scheduled_time": datetime.now(UTC)}
{"pyrat_task_scheduled_time": datetime.now(timezone.utc)}
)
time.sleep(1)
self.insert1(key)
Expand Down

0 comments on commit cc7e759

Please sign in to comment.