Skip to content
Merged
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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Formatted and linted with `ruff` (rules: E, F, I, UP; line-length not enforced).
pre-commit run --all-files
```

- Python ≥ 3.10
- Python ≥ 3.11
- Type hints throughout; use `X | Y` union syntax (PEP 604), not `Optional`/`Union`
- Google-style docstrings with `Args:` and `Returns:` sections
- No inline comments unless the *why* is non-obvious
Expand Down
1 change: 1 addition & 0 deletions documentation/reference/changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Breaking Changes
From 6.7.7, Python 3.11 or later is required

From 6.6.5, removed DatasetTitleHelper class and Dataset method remove_dates_from_title

Expand Down
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
Expand All @@ -33,14 +32,14 @@ classifiers = [
]
readme = "README.md"
dynamic = ["version"]
requires-python = ">=3.10"
requires-python = ">=3.11"

dependencies = [
"ckanapi>=4.11",
"defopt>=7.0.0",
"email_validator",
"hdx-python-country>=4.2.5",
"hdx-python-utilities>=4.2.4",
"hdx-python-country>=4.2.6",
"hdx-python-utilities>=4.2.5",
"makefun",
"requests",
]
Expand Down Expand Up @@ -87,7 +86,7 @@ allow-direct-references = true
# ----------------------------------------------------------------------------

[tool.ruff]
target-version = "py310"
target-version = "py311"
src = ["src"]
exclude = ["_version.py"]

Expand Down
10 changes: 5 additions & 5 deletions src/hdx/api/utilities/date_helper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Helper to the Dataset and Resource classes for handling HDX dates."""

from collections.abc import Iterable
from datetime import datetime, timezone
from datetime import UTC, datetime

from hdx.utilities.dateparse import now_utc, parse_date

Expand Down Expand Up @@ -52,7 +52,7 @@ def get_hdx_date(
microsecond=0,
)
else:
date = date.astimezone(timezone.utc)
date = date.astimezone(UTC)
if include_microseconds:
timespec = "microseconds"
else:
Expand Down Expand Up @@ -92,7 +92,7 @@ def get_time_period_info(
hour=23,
minute=59,
second=59,
tzinfo=timezone.utc,
tzinfo=UTC,
)
ongoing = True
else:
Expand Down Expand Up @@ -179,8 +179,8 @@ def get_hdx_time_period_from_years(
retval = sorted(int(x) for x in list(startyear))
startyear = retval[0]
endyear = retval[-1]
startdate = datetime(startyear, 1, 1, tzinfo=timezone.utc)
enddate = datetime(endyear, 12, 31, 23, 59, 59, tzinfo=timezone.utc)
startdate = datetime(startyear, 1, 1, tzinfo=UTC)
enddate = datetime(endyear, 12, 31, 23, 59, 59, tzinfo=UTC)
return (
cls.get_hdx_time_period(startdate, enddate, ignore_timeinfo=False),
retval,
Expand Down
6 changes: 3 additions & 3 deletions tests/hdx/api/utilities/test_hdx_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import json
from copy import deepcopy
from datetime import datetime, timezone
from datetime import UTC, datetime
from os import makedirs
from os.path import exists
from pathlib import Path
Expand Down Expand Up @@ -37,11 +37,11 @@ def multidatestatefile(self):

@pytest.fixture(scope="class")
def date1(self):
return datetime(2020, 9, 23, 0, 0, tzinfo=timezone.utc)
return datetime(2020, 9, 23, 0, 0, tzinfo=UTC)

@pytest.fixture(scope="class")
def date2(self):
return datetime(2022, 5, 12, 10, 15, tzinfo=timezone.utc)
return datetime(2022, 5, 12, 10, 15, tzinfo=UTC)

@pytest.fixture(scope="function")
def do_state(self, tempfolder, statefile):
Expand Down
18 changes: 9 additions & 9 deletions tests/hdx/data/test_dataset_noncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import copy
import json
from datetime import datetime, timezone
from datetime import UTC, datetime

import pytest
from hdx.location.country import Country
Expand Down Expand Up @@ -348,35 +348,35 @@ def test_get_set_date_of_dataset(self, configuration):
dataset = Dataset({"dataset_date": "[2020-01-07T00:00:00 TO *]"})
result = dataset.get_time_period(today=datetime(2020, 11, 17))
assert result == {
"startdate": datetime(2020, 1, 7, 0, 0, tzinfo=timezone.utc),
"enddate": datetime(2020, 11, 17, 23, 59, 59, tzinfo=timezone.utc),
"startdate": datetime(2020, 1, 7, 0, 0, tzinfo=UTC),
"enddate": datetime(2020, 11, 17, 23, 59, 59, tzinfo=UTC),
"startdate_str": "2020-01-07T00:00:00+00:00",
"enddate_str": "2020-11-17T23:59:59+00:00",
"ongoing": True,
}
dataset.set_time_period("2020-02-09")
result = dataset.get_time_period("%d/%m/%Y")
assert result == {
"startdate": datetime(2020, 2, 9, 0, 0, tzinfo=timezone.utc),
"enddate": datetime(2020, 2, 9, 23, 59, 59, tzinfo=timezone.utc),
"startdate": datetime(2020, 2, 9, 0, 0, tzinfo=UTC),
"enddate": datetime(2020, 2, 9, 23, 59, 59, tzinfo=UTC),
"startdate_str": "09/02/2020",
"enddate_str": "09/02/2020",
"ongoing": False,
}
dataset.set_time_period("2020-02-09", "2020-10-20")
result = dataset.get_time_period("%d/%m/%Y")
assert result == {
"startdate": datetime(2020, 2, 9, 0, 0, tzinfo=timezone.utc),
"enddate": datetime(2020, 10, 20, 23, 59, 59, tzinfo=timezone.utc),
"startdate": datetime(2020, 2, 9, 0, 0, tzinfo=UTC),
"enddate": datetime(2020, 10, 20, 23, 59, 59, tzinfo=UTC),
"startdate_str": "09/02/2020",
"enddate_str": "20/10/2020",
"ongoing": False,
}
dataset.set_time_period("2020-02-09", ongoing=True)
result = dataset.get_time_period("%d/%m/%Y", today=datetime(2020, 3, 9, 0, 0))
assert result == {
"startdate": datetime(2020, 2, 9, 0, 0, tzinfo=timezone.utc),
"enddate": datetime(2020, 3, 9, 23, 59, 59, tzinfo=timezone.utc),
"startdate": datetime(2020, 2, 9, 0, 0, tzinfo=UTC),
"enddate": datetime(2020, 3, 9, 23, 59, 59, tzinfo=UTC),
"startdate_str": "09/02/2020",
"enddate_str": "09/03/2020",
"ongoing": True,
Expand Down
16 changes: 7 additions & 9 deletions tests/hdx/data/test_dataset_resource_generation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Dataset Tests (noncore methods)"""

from datetime import datetime, timezone
from datetime import UTC, datetime

import pytest
from hdx.utilities.compare import assert_files_same
Expand Down Expand Up @@ -73,8 +73,8 @@ def process_row(headers, row):
]
assert success is True
assert results == {
"startdate": datetime(2001, 1, 1, 0, 0, tzinfo=timezone.utc),
"enddate": datetime(2002, 12, 31, 23, 59, 59, tzinfo=timezone.utc),
"startdate": datetime(2001, 1, 1, 0, 0, tzinfo=UTC),
"enddate": datetime(2002, 12, 31, 23, 59, 59, tzinfo=UTC),
"resource": {
"description": "Conflict data",
"format": "csv",
Expand Down Expand Up @@ -289,8 +289,8 @@ def process_row(headers, row):
)
assert success is True
assert results == {
"startdate": datetime(2001, 1, 1, 0, 0, tzinfo=timezone.utc),
"enddate": datetime(2002, 12, 31, 23, 59, 59, tzinfo=timezone.utc),
"startdate": datetime(2001, 1, 1, 0, 0, tzinfo=UTC),
"enddate": datetime(2002, 12, 31, 23, 59, 59, tzinfo=UTC),
"resource": {
"description": "Conflict data",
"format": "csv",
Expand Down Expand Up @@ -433,11 +433,9 @@ def process_year(row):
date_function=process_year,
)
assert success is True
assert results["startdate"] == datetime(
2001, 1, 1, 0, 0, tzinfo=timezone.utc
)
assert results["startdate"] == datetime(2001, 1, 1, 0, 0, tzinfo=UTC)
assert results["enddate"] == datetime(
2001, 12, 31, 23, 59, 59, tzinfo=timezone.utc
2001, 12, 31, 23, 59, 59, tzinfo=UTC
)
assert (
dataset["dataset_date"]
Expand Down
10 changes: 5 additions & 5 deletions tests/hdx/data/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import logging
import os
from datetime import datetime, timezone
from datetime import UTC, datetime
from os import remove
from os.path import basename
from pathlib import Path
Expand Down Expand Up @@ -912,17 +912,17 @@ def test_get_set_date_of_resource(self, configuration):
resource = Resource({"daterange_for_data": "[2020-01-07T00:00:00 TO *]"})
result = resource.get_date_of_resource(today=datetime(2020, 11, 17))
assert result == {
"startdate": datetime(2020, 1, 7, 0, 0, tzinfo=timezone.utc),
"enddate": datetime(2020, 11, 17, 23, 59, 59, tzinfo=timezone.utc),
"startdate": datetime(2020, 1, 7, 0, 0, tzinfo=UTC),
"enddate": datetime(2020, 11, 17, 23, 59, 59, tzinfo=UTC),
"startdate_str": "2020-01-07T00:00:00+00:00",
"enddate_str": "2020-11-17T23:59:59+00:00",
"ongoing": True,
}
resource.set_date_of_resource("2020-02-09", "2020-10-20")
result = resource.get_date_of_resource("%d/%m/%Y")
assert result == {
"startdate": datetime(2020, 2, 9, 0, 0, tzinfo=timezone.utc),
"enddate": datetime(2020, 10, 20, 23, 59, 59, tzinfo=timezone.utc),
"startdate": datetime(2020, 2, 9, 0, 0, tzinfo=UTC),
"enddate": datetime(2020, 10, 20, 23, 59, 59, tzinfo=UTC),
"startdate_str": "09/02/2020",
"enddate_str": "20/10/2020",
"ongoing": False,
Expand Down
Loading
Loading