Skip to content

Commit ae58df6

Browse files
committed
- Replace timezonefinder with tzfpy for improved performance
- Update Python compatibility to 3.11+ - Bump version to 0.0.14
1 parent b4e6931 commit ae58df6

5 files changed

Lines changed: 458 additions & 626 deletions

File tree

.github/workflows/branch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
strategy:
3434
fail-fast: false
3535
matrix:
36-
python-version: ['3.10', '3.11', '3.12', '3.13']
36+
python-version: ['3.11', '3.12', '3.13']
3737

3838
steps:
3939
- uses: actions/checkout@v4

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# NGI Python Coordinate Projector Package
22

33

4+
## Version 0.0.14
5+
_2025-08-19_
6+
7+
Internal
8+
9+
- Replace the package `timezonefinder` with `tzfpy` for improved performance.
10+
411
## Version 0.0.13
512
_2025-05-21_
613

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[project]
22
name = "coordinate-projector"
3-
version = "0.0.13"
3+
version = "0.0.14"
44
description = "Project points from one projection to another using pyproj"
55
authors = [
66
{ name = "Helge Smebye" },
77
{ name = "Jostein Leira", email = "jostein@leira.net" },
88
]
9-
requires-python = ">=3.10,<4"
9+
requires-python = ">=3.11,<4"
1010
readme = "README.md"
1111
license = "MIT"
1212
maintainers = [{ name = "Jostein Leira", email = "jostein@leira.net" }]
@@ -20,7 +20,7 @@ dependencies = [
2020
"pyproj>=3.6.1,<4",
2121
"python-dateutil>=2.8.2,<3",
2222
"types-python-dateutil>=2.8.19,<3",
23-
"timezonefinder",
23+
"tzfpy[tzdata]>=1.0.0",
2424
]
2525

2626
[project.urls]

src/coordinate_projector/datetime_parser.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
"""
44

55
from datetime import datetime
6-
6+
from zoneinfo import ZoneInfo
77

88
from dateutil import tz
9-
from timezonefinder import TimezoneFinder
9+
from tzfpy import get_tz
1010

1111
from coordinate_projector.projector import Projector
1212

1313
projector = Projector()
1414

15-
_time_zone_finder: TimezoneFinder | None = None
16-
1715

1816
def ensure_tz(
1917
dt: datetime | None,
@@ -32,13 +30,11 @@ def ensure_tz(
3230
If no location or timezone is provided, then assume the passed datetime is
3331
recorded in the norwegian timezone.
3432
"""
35-
global _time_zone_finder
36-
3733
if not dt:
3834
return dt
3935

4036
if not isinstance(dt, datetime):
41-
raise Exception("Got unexpected type for datetime!")
37+
raise TypeError("Got unexpected type for datetime!")
4238

4339
if dt.tzinfo is None or dt.tzinfo.utcoffset(dt) is None:
4440
# timezone naive (no time zone in dt)
@@ -47,15 +43,12 @@ def ensure_tz(
4743
longitude, latitude = projector.transform(from_srid=srid, to_srid=4326, east=longitude, north=latitude)
4844

4945
# find timezone from position
50-
if not _time_zone_finder:
51-
_time_zone_finder = TimezoneFinder()
52-
53-
input_timezone = tz.gettz(_time_zone_finder.timezone_at(lng=longitude, lat=latitude))
46+
input_timezone = get_tz(lng=longitude, lat=latitude)
5447
else:
5548
# Assume Norway
56-
input_timezone = tz.gettz("Europe/Oslo")
49+
input_timezone = "Europe/Oslo"
5750

58-
dt = dt.replace(tzinfo=input_timezone)
51+
dt = dt.replace(tzinfo=ZoneInfo(input_timezone))
5952

6053
return dt
6154

0 commit comments

Comments
 (0)