Skip to content

Commit

Permalink
fixup: define itertools.pairwise for python < 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
pmav99 committed Jan 29, 2024
1 parent 3c0c3f0 commit 6a598b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions searvey/ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import collections
import functools
import io
import itertools
import logging
import typing as T
import warnings
Expand Down Expand Up @@ -48,6 +47,7 @@
from .utils import get_region
from .utils import merge_datasets
from .utils import NOW
from .utils import pairwise
from .utils import resolve_timestamp


Expand Down Expand Up @@ -498,7 +498,7 @@ def _generate_urls(
periods = duration.days // 30 + 2
urls = []
date_range = pd.date_range(start_date, end_date, periods=periods, unit="us", inclusive="both")
for start, stop in itertools.pairwise(date_range):
for start, stop in pairwise(date_range):
timestart = _ioc_date(start)
timestop = _ioc_date(stop)
url = BASE_URL.format(ioc_code=station_id, timestart=timestart, timestop=timestop)
Expand Down
14 changes: 12 additions & 2 deletions searvey/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import itertools
import typing as T
from typing import Dict
from typing import Final
from typing import Iterable
Expand All @@ -25,11 +26,20 @@

NOW: Final = "now"

try:
from itertools import pairwise
except ImportError:

Check warning on line 31 in searvey/utils.py

View check run for this annotation

Codecov / codecov/patch

searvey/utils.py#L31

Added line #L31 was not covered by tests

def pairwise(iterable: T.Iterable[_T]) -> T.Iterator[tuple[_T, _T]]:

Check warning on line 33 in searvey/utils.py

View check run for this annotation

Codecov / codecov/patch

searvey/utils.py#L33

Added line #L33 was not covered by tests
# pairwise('ABCDEFG') --> AB BC CD DE EF FG
a, b = itertools.tee(iterable)
next(b, None)
return zip(a, b)

Check warning on line 37 in searvey/utils.py

View check run for this annotation

Codecov / codecov/patch

searvey/utils.py#L35-L37

Added lines #L35 - L37 were not covered by tests


# https://gis.stackexchange.com/questions/201789/verifying-formula-that-will-convert-longitude-0-360-to-180-to-180
# lon1 is the longitude varying from -180 to 180 or 180W-180E
# lon3 is the longitude variable from 0 to 360 (all positive)


def lon1_to_lon3(lon1: ScalarOrArray) -> ScalarOrArray:
return lon1 % 360

Expand Down

0 comments on commit 6a598b5

Please sign in to comment.