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 ff53cd5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 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
11 changes: 11 additions & 0 deletions searvey/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
# lon1 is the longitude varying from -180 to 180 or 180W-180E
# lon3 is the longitude variable from 0 to 360 (all positive)

try:
from itertools import pairwise
except ImportError:
from itertools import tee

def pairwise(iterable):
# pairwise('ABCDEFG') --> AB BC CD DE EF FG
a, b = tee(iterable)
next(b, None)
return zip(a, b)


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

0 comments on commit ff53cd5

Please sign in to comment.