Skip to content

Commit

Permalink
Do not use the deprecated utcnow (#1283)
Browse files Browse the repository at this point in the history
* Do not use the deprecated utcnow

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Pete Gadomski <[email protected]>
  • Loading branch information
avalentino and gadomski authored Nov 27, 2023
1 parent c2c1d3c commit 967ce91
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- No longer use the `datetime.utcnow` method that has been deprecated in Python 3.12 ([#1283](https://github.com/stac-utils/pystac/pull/1283))

## [v1.9.0] - 2023-10-23

### Added
Expand Down
4 changes: 2 additions & 2 deletions pystac/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import warnings
from collections.abc import Iterable
from copy import deepcopy
from datetime import datetime
from datetime import datetime, timezone
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -294,7 +294,7 @@ def from_now() -> TemporalExtent:
TemporalExtent: The resulting TemporalExtent.
"""
return TemporalExtent(
intervals=[[datetime.utcnow().replace(microsecond=0), None]]
intervals=[[datetime.now(timezone.utc).replace(microsecond=0), None]]
)


Expand Down
28 changes: 14 additions & 14 deletions tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from collections import defaultdict
from collections.abc import Iterator
from copy import deepcopy
from datetime import datetime
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, cast

Expand Down Expand Up @@ -140,7 +140,7 @@ def test_clear_items_removes_from_cache(self) -> None:
id="test-item",
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties={"key": "one"},
)
subcat.add_item(item)
Expand All @@ -154,7 +154,7 @@ def test_clear_items_removes_from_cache(self) -> None:
id="test-item",
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties={"key": "two"},
)
subcat.add_item(item)
Expand All @@ -168,7 +168,7 @@ def test_clear_items_removes_from_cache(self) -> None:
id="test-item",
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties={"key": "three"},
)
subcat.add_item(item)
Expand Down Expand Up @@ -710,7 +710,7 @@ def test_generate_subcatalogs_merge_template_elements(self) -> None:
id=f"item{ni}",
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties=properties,
)
)
Expand Down Expand Up @@ -748,7 +748,7 @@ def test_generate_subcatalogs_works_after_adding_more_items(self) -> None:
id="item1",
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties=properties,
)
)
Expand All @@ -758,7 +758,7 @@ def test_generate_subcatalogs_works_after_adding_more_items(self) -> None:
id="item2",
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties=properties,
)
)
Expand Down Expand Up @@ -787,7 +787,7 @@ def test_generate_subcatalogs_works_for_branched_subcatalogs(self) -> None:
id=f"item{ni}",
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties=properties,
)
)
Expand All @@ -812,7 +812,7 @@ def test_generate_subcatalogs_works_for_subcatalogs_with_same_ids(self) -> None:
id=f"item{ni}",
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties=properties,
)
)
Expand Down Expand Up @@ -896,7 +896,7 @@ def test_map_items_multiple_2(self) -> None:
id="item1",
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties={},
)
item1.add_asset("ortho", Asset(href="/some/ortho.tif"))
Expand All @@ -907,7 +907,7 @@ def test_map_items_multiple_2(self) -> None:
id="item2",
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties={},
)
item2.add_asset("ortho", Asset(href="/some/other/ortho.tif"))
Expand Down Expand Up @@ -1436,7 +1436,7 @@ def test_full_copy_1(self) -> None:
id="test_item",
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties={},
)

Expand All @@ -1456,7 +1456,7 @@ def test_full_copy_2(self) -> None:
id="Imagery",
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties={},
)
for key in ["ortho", "dsm"]:
Expand All @@ -1469,7 +1469,7 @@ def test_full_copy_2(self) -> None:
id="Labels",
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties={},
)
cat.add_items([image_item, label_item])
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/test_cases.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import csv
import os
from datetime import datetime
from datetime import datetime, timezone
from typing import Any

import pystac
Expand Down Expand Up @@ -156,7 +156,7 @@ def case_3() -> Catalog:
id="imagery-item",
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties={},
)

Expand All @@ -168,7 +168,7 @@ def case_3() -> Catalog:
id="label-items",
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties={},
)

Expand Down
4 changes: 2 additions & 2 deletions tests/validation/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import shutil
import tempfile
from datetime import datetime
from datetime import datetime, timezone
from typing import Any

import jsonschema
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_validates_geojson_with_tuple_coordinates(self) -> None:
id="test-item",
geometry=geom,
bbox=[-115.308, 36.126, -115.305, 36.129],
datetime=datetime.utcnow(),
datetime=datetime.now(timezone.utc),
properties={},
)

Expand Down

0 comments on commit 967ce91

Please sign in to comment.