Skip to content

Commit

Permalink
Replace occurrences of dt.timezone.utc by ZoneInfo("UTC")
Browse files Browse the repository at this point in the history
  • Loading branch information
gutzbenj committed Dec 30, 2024
1 parent b196bc9 commit 2ac658d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Restapi/Cli: Use pydantic models for request parameters
- Rename `dropna` to `drop_nulls`
- Change default of `drop_nulls` to True
- Replace occurrences of `dt.timezone.utc` by `ZoneInfo("UTC")`

## 0.98.0 - 2024-12-09

Expand Down
44 changes: 22 additions & 22 deletions tests/provider/dwd/observation/test_api_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def test_dwd_observations_urban_values(default_settings):
"humidity",
"temperature_air_mean_2m",
],
"date": [dt.datetime(2022, 6, 1, tzinfo=dt.timezone.utc)] * 2,
"date": [dt.datetime(2022, 6, 1, tzinfo=ZoneInfo("UTC"))] * 2,
"value": [
83.0,
286.54999999999995,
Expand Down Expand Up @@ -790,55 +790,55 @@ def test_dwd_observation_data_10_minutes_result_tidy(settings_humanize_si_false)
"station_id": "01048",
"dataset": "temperature_air",
"parameter": "pp_10",
"date": dt.datetime(1999, 12, 31, 21, 00, tzinfo=dt.timezone.utc),
"date": dt.datetime(1999, 12, 31, 21, 00, tzinfo=ZoneInfo("UTC")),
"value": 996.0,
"quality": 1.0,
},
{
"station_id": "01048",
"dataset": "temperature_air",
"parameter": "pp_10",
"date": dt.datetime(1999, 12, 31, 21, 10, tzinfo=dt.timezone.utc),
"date": dt.datetime(1999, 12, 31, 21, 10, tzinfo=ZoneInfo("UTC")),
"value": 995.9,
"quality": 1.0,
},
{
"station_id": "01048",
"dataset": "temperature_air",
"parameter": "pp_10",
"date": dt.datetime(1999, 12, 31, 21, 20, tzinfo=dt.timezone.utc),
"date": dt.datetime(1999, 12, 31, 21, 20, tzinfo=ZoneInfo("UTC")),
"value": 995.9,
"quality": 1.0,
},
{
"station_id": "01048",
"dataset": "temperature_air",
"parameter": "pp_10",
"date": dt.datetime(1999, 12, 31, 21, 30, tzinfo=dt.timezone.utc),
"date": dt.datetime(1999, 12, 31, 21, 30, tzinfo=ZoneInfo("UTC")),
"value": 996.0,
"quality": 1.0,
},
{
"station_id": "01048",
"dataset": "temperature_air",
"parameter": "pp_10",
"date": dt.datetime(1999, 12, 31, 21, 40, tzinfo=dt.timezone.utc),
"date": dt.datetime(1999, 12, 31, 21, 40, tzinfo=ZoneInfo("UTC")),
"value": 996.0,
"quality": 1.0,
},
{
"station_id": "01048",
"dataset": "temperature_air",
"parameter": "pp_10",
"date": dt.datetime(1999, 12, 31, 21, 50, tzinfo=dt.timezone.utc),
"date": dt.datetime(1999, 12, 31, 21, 50, tzinfo=ZoneInfo("UTC")),
"value": 996.0,
"quality": 1.0,
},
{
"station_id": "01048",
"dataset": "temperature_air",
"parameter": "pp_10",
"date": dt.datetime(1999, 12, 31, 22, 00, tzinfo=dt.timezone.utc),
"date": dt.datetime(1999, 12, 31, 22, 00, tzinfo=ZoneInfo("UTC")),
"value": 996.1,
"quality": 1.0,
},
Expand Down Expand Up @@ -872,95 +872,95 @@ def test_dwd_observation_data_monthly_tidy(default_settings):
"station_id": "00433",
"dataset": "climate_summary",
"parameter": "precipitation_height",
"date": dt.datetime(2020, 1, 1, tzinfo=dt.timezone.utc),
"date": dt.datetime(2020, 1, 1, tzinfo=ZoneInfo("UTC")),
"value": 34.0,
"quality": 9.0,
},
{
"station_id": "00433",
"dataset": "climate_summary",
"parameter": "precipitation_height",
"date": dt.datetime(2020, 2, 1, tzinfo=dt.timezone.utc),
"date": dt.datetime(2020, 2, 1, tzinfo=ZoneInfo("UTC")),
"value": 83.2,
"quality": 9.0,
},
{
"station_id": "00433",
"dataset": "climate_summary",
"parameter": "precipitation_height",
"date": dt.datetime(2020, 3, 1, tzinfo=dt.timezone.utc),
"date": dt.datetime(2020, 3, 1, tzinfo=ZoneInfo("UTC")),
"value": 30.3,
"quality": 9.0,
},
{
"station_id": "00433",
"dataset": "climate_summary",
"parameter": "precipitation_height",
"date": dt.datetime(2020, 4, 1, tzinfo=dt.timezone.utc),
"date": dt.datetime(2020, 4, 1, tzinfo=ZoneInfo("UTC")),
"value": 22.7,
"quality": 9.0,
},
{
"station_id": "00433",
"dataset": "climate_summary",
"parameter": "precipitation_height",
"date": dt.datetime(2020, 5, 1, tzinfo=dt.timezone.utc),
"date": dt.datetime(2020, 5, 1, tzinfo=ZoneInfo("UTC")),
"value": 33.3,
"quality": 9.0,
},
{
"station_id": "00433",
"dataset": "climate_summary",
"parameter": "precipitation_height",
"date": dt.datetime(2020, 6, 1, tzinfo=dt.timezone.utc),
"date": dt.datetime(2020, 6, 1, tzinfo=ZoneInfo("UTC")),
"value": 35.8,
"quality": 9.0,
},
{
"station_id": "00433",
"dataset": "climate_summary",
"parameter": "precipitation_height",
"date": dt.datetime(2020, 7, 1, tzinfo=dt.timezone.utc),
"date": dt.datetime(2020, 7, 1, tzinfo=ZoneInfo("UTC")),
"value": 46.8,
"quality": 9.0,
},
{
"station_id": "00433",
"dataset": "climate_summary",
"parameter": "precipitation_height",
"date": dt.datetime(2020, 8, 1, tzinfo=dt.timezone.utc),
"date": dt.datetime(2020, 8, 1, tzinfo=ZoneInfo("UTC")),
"value": 43.2,
"quality": 9.0,
},
{
"station_id": "00433",
"dataset": "climate_summary",
"parameter": "precipitation_height",
"date": dt.datetime(2020, 9, 1, tzinfo=dt.timezone.utc),
"date": dt.datetime(2020, 9, 1, tzinfo=ZoneInfo("UTC")),
"value": 52.8,
"quality": 9.0,
},
{
"station_id": "00433",
"dataset": "climate_summary",
"parameter": "precipitation_height",
"date": dt.datetime(2020, 10, 1, tzinfo=dt.timezone.utc),
"date": dt.datetime(2020, 10, 1, tzinfo=ZoneInfo("UTC")),
"value": 58.2,
"quality": 9.0,
},
{
"station_id": "00433",
"dataset": "climate_summary",
"parameter": "precipitation_height",
"date": dt.datetime(2020, 11, 1, tzinfo=dt.timezone.utc),
"date": dt.datetime(2020, 11, 1, tzinfo=ZoneInfo("UTC")),
"value": 16.4,
"quality": 9.0,
},
{
"station_id": "00433",
"dataset": "climate_summary",
"parameter": "precipitation_height",
"date": dt.datetime(2020, 12, 1, tzinfo=dt.timezone.utc),
"date": dt.datetime(2020, 12, 1, tzinfo=ZoneInfo("UTC")),
"value": 22.1,
"quality": 9.0,
},
Expand Down Expand Up @@ -1173,8 +1173,8 @@ def test_dwd_observation_weather_phenomena(settings_humanize_si_false):
"""
request = DwdObservationRequest(
parameters=[("hourly", "weather_phenomena")],
start_date=dt.datetime(year=2022, month=3, day=1, tzinfo=dt.timezone.utc),
end_date=dt.datetime(year=2022, month=3, day=31, tzinfo=dt.timezone.utc),
start_date=dt.datetime(year=2022, month=3, day=1, tzinfo=ZoneInfo("UTC")),
end_date=dt.datetime(year=2022, month=3, day=31, tzinfo=ZoneInfo("UTC")),
settings=settings_humanize_si_false,
)
given_df = request.all().df.drop_nulls()
Expand Down
5 changes: 3 additions & 2 deletions wetterdienst/provider/geosphere/observation/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
from datetime import datetime, timedelta
from typing import TYPE_CHECKING
from zoneinfo import ZoneInfo

import polars as pl

Expand Down Expand Up @@ -59,8 +60,8 @@ def _collect_station_parameter_or_dataset(
station_id=station_id,
parameters=",".join(parameters),
dataset=parameter_or_dataset.name_original,
start_date=start_date.astimezone(dt.timezone.utc).strftime("%Y-%m-%dT%H:%m"),
end_date=end_date.astimezone(dt.timezone.utc).strftime("%Y-%m-%dT%H:%m"),
start_date=start_date.astimezone(ZoneInfo("UTC")).strftime("%Y-%m-%dT%H:%m"),
end_date=end_date.astimezone(ZoneInfo("UTC")).strftime("%Y-%m-%dT%H:%m"),
)
log.info(f"Downloading file {url}.")
response = download_file(url=url, settings=self.sr.stations.settings, ttl=CacheExpiry.FIVE_MINUTES)
Expand Down
3 changes: 2 additions & 1 deletion wetterdienst/util/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import datetime as dt
from zoneinfo import ZoneInfo

from dateutil.relativedelta import relativedelta

Expand Down Expand Up @@ -101,5 +102,5 @@ def parse_date(date_string):
if not date_parsed:
raise ValueError(f"date_string {date_string} could not be parsed")
if date_parsed and not date_parsed.tzinfo:
date_parsed = date_parsed.replace(tzinfo=dt.timezone.utc)
date_parsed = date_parsed.replace(tzinfo=ZoneInfo("UTC"))
return date_parsed

0 comments on commit 2ac658d

Please sign in to comment.