Skip to content

refactor: replace usage of pytz with zoneinfo#475

Open
asmfstatoil wants to merge 1 commit into
mainfrom
replace_pytz
Open

refactor: replace usage of pytz with zoneinfo#475
asmfstatoil wants to merge 1 commit into
mainfrom
replace_pytz

Conversation

@asmfstatoil

Copy link
Copy Markdown
Collaborator

No description provided.

@asmfstatoil asmfstatoil changed the title refact: replace usage of pytz with zoneinfo refactor: replace usage of pytz with zoneinfo Jun 11, 2026
@asmfstatoil asmfstatoil requested a review from Copilot June 17, 2026 06:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors Tagreader’s timezone handling to remove the pytz dependency and use Python’s built-in zoneinfo instead, updating runtime code, tests, and documentation accordingly.

Changes:

  • Replaced pytz timezone usage with zoneinfo.ZoneInfo and datetime.timezone.utc in core code paths.
  • Updated tests to construct/compare timezone-aware datetimes using ZoneInfo, and refreshed docs/examples to use IANA zone names (e.g., America/Sao_Paulo).
  • Minor cleanup (tuple unpacking style, timedelta slicing simplification).

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tagreader/utils.py Switches default timezone handling to ZoneInfo and updates naive-datetime tz attachment logic.
tagreader/clients.py Updates client timezone parsing/validation to use ZoneInfo and removes pytz usage.
tagreader/web_handlers.py Replaces pytz.UTC conversions with datetime.timezone.utc.
tagreader/cache.py Replaces pytz.utc conversion with datetime.timezone.utc.
tests/test_utils.py Updates datetime-with-timezone assertions to use ZoneInfo.
tests/test_clients.py Updates timezone expectations to ZoneInfo.
tests/test_PIHandlerREST.py Minor tuple unpacking cleanup in tests.
tests/test_bucketcache.py Simplifies timestamp slicing using TS directly.
tests/test_AspenHandlerREST_connect.py Adjusts test time constants.
documentation/docs/about/usage/time-zone.md Updates timezone guidance from pytz to zoneinfo/tzdata.
documentation/docs/about/usage/basic-usage.md Updates example timezone string to America/Sao_Paulo.
docs/manual.md Updates manual to reflect zoneinfo usage and updated examples.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tagreader/utils.py
Comment on lines 51 to 55
def ensure_datetime_with_tz(
date_stamp: Union[datetime, str, pd.Timestamp],
tz: tzinfo = pytz.timezone("Europe/Oslo"),
tz: tzinfo = ZoneInfo("Europe/Oslo"),
) -> datetime:
date_stamp = convert_to_pydatetime(date_stamp)
Comment thread tagreader/clients.py
datasource: str,
imstype: Optional[Union[str, IMSType]] = None,
tz: Union[tzinfo, str] = pytz.timezone("Europe/Oslo"),
tz: Union[tzinfo, str] = ZoneInfo("Europe/Oslo"),
Comment thread tagreader/clients.py
Comment on lines +214 to +218
self.tz = ZoneInfo(tz)
except ZoneInfoNotFoundError:
raise ValueError(
f"Invalid timezone string. Given type was {type(tz)}"
) from None
Comment thread tests/test_utils.py
Comment on lines 26 to +28
assert ensure_datetime_with_tz(
"02.01.03 00:00:00", pytz.timezone("Brazil/East")
) == timezone("Brazil/East").localize(datetime.datetime(2003, 1, 2, 0, 0, 0))
"02.01.03 00:00:00", ZoneInfo("America/Sao_Paulo")
) == datetime.datetime(2003, 1, 2, 0, 0, 0, tzinfo=ZoneInfo("America/Sao_Paulo"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants