Skip to content

Commit

Permalink
replace utcnow to avoid deprecation warnings in python 3.12 (#8051)
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram authored Nov 22, 2023
1 parent 7611a4c commit e674c9d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ outlier_detection
- Remove use of ``scipy.signal.medfilt`` which is undefined for ``nan``
inputs. [#8033]

- Replace uses of ``datetime.utcnow`` (deprecated in python 3.12) [#8051]

imprint
-------

Expand Down
4 changes: 2 additions & 2 deletions jwst/associations/association.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import MutableMapping
from copy import deepcopy
from datetime import datetime
from datetime import datetime, timezone
import json
import jsonschema
import logging
Expand Down Expand Up @@ -564,7 +564,7 @@ def finalize(asns):


def make_timestamp():
timestamp = datetime.utcnow().strftime(
timestamp = datetime.now(timezone.utc).strftime(
_TIMESTAMP_TEMPLATE
)
return timestamp
Expand Down
5 changes: 3 additions & 2 deletions jwst/scripts/migrate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Migrate .fits files whose format has changed between jwst package versions.
"""
import argparse
from datetime import datetime
from datetime import datetime, timezone
import os
import re
import traceback
Expand Down Expand Up @@ -166,7 +166,8 @@ def migrate_file(filename, args):
return

migrate_method(hdul)
hdul[0].header['HISTORY'] = f'Migrated with jwst {jwst.__version__} migrate_data script {datetime.utcnow().isoformat()}'
timestamp = datetime.now(timezone.utc).isoformat()
hdul[0].header['HISTORY'] = f'Migrated with jwst {jwst.__version__} migrate_data script {timestamp}'

try:
getattr(datamodels, model_type)(hdul, strict_validation=True)
Expand Down
5 changes: 3 additions & 2 deletions jwst/stpipe/tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

import pytest
import asdf
Expand Down Expand Up @@ -56,7 +56,8 @@ def test_step_config_to_asdf(config):
assert asdf_file["parameters"] == config.parameters
assert asdf_file["steps"] == [s.to_asdf().tree for s in config.steps]
assert asdf_file["meta"]["author"] == "<SPECIFY>"
assert (datetime.utcnow() - datetime.fromisoformat(asdf_file["meta"]["date"])) < timedelta(seconds=10)
current_time = datetime.now(timezone.utc).replace(tzinfo=None)
assert (current_time - datetime.fromisoformat(asdf_file["meta"]["date"])) < timedelta(seconds=10)
assert asdf_file["meta"]["description"] == "Parameters for calibration step some.PipelineClass"
assert asdf_file["meta"]["instrument"]["name"] == "<SPECIFY>"
assert asdf_file["meta"]["origin"] == "<SPECIFY>"
Expand Down

0 comments on commit e674c9d

Please sign in to comment.