Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 6054dbc

Browse files
committed
Fix for Python 3.7
1 parent 0fa11c7 commit 6054dbc

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

data_diff/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from abc import ABC, abstractmethod
66
from urllib.parse import urlparse
77
from uuid import UUID
8+
import operator
89
import string
910

1011
alphanums = string.digits + string.ascii_lowercase
@@ -221,3 +222,19 @@ def match_like(pattern: str, strs: Sequence[str]) -> Iterable[str]:
221222
for s in strs:
222223
if reo.match(s):
223224
yield s
225+
226+
227+
def accumulate(iterable, func=operator.add, *, initial=None):
228+
'Return running totals'
229+
# Taken from https://docs.python.org/3/library/itertools.html#itertools.accumulate, to backport 'initial' to 3.7
230+
it = iter(iterable)
231+
total = initial
232+
if initial is None:
233+
try:
234+
total = next(it)
235+
except StopIteration:
236+
return
237+
yield total
238+
for element in it:
239+
total = func(total, element)
240+
yield total

tests/test_database_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
from datetime import datetime, timedelta, timezone
99
import logging
1010
from decimal import Decimal
11-
from itertools import islice, accumulate, repeat, chain
11+
from itertools import islice, repeat, chain
1212

1313
from parameterized import parameterized
1414

1515
from data_diff import databases as db
1616
from data_diff.databases import postgresql, oracle
17-
from data_diff.utils import number_to_human
17+
from data_diff.utils import number_to_human, accumulate
1818
from data_diff.diff_tables import TableDiffer, TableSegment, DEFAULT_BISECTION_THRESHOLD
1919
from .common import (
2020
CONN_STRINGS,

0 commit comments

Comments
 (0)