Skip to content

Commit 060fa0d

Browse files
committed
Intermediate changes
commit_hash:8c2a03558616560deb74e3412a33769b4f519a0a
1 parent aa3922e commit 060fa0d

File tree

8 files changed

+400
-81
lines changed

8 files changed

+400
-81
lines changed

contrib/python/more-itertools/py3/.dist-info/METADATA

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
Metadata-Version: 2.1
22
Name: more-itertools
3-
Version: 10.5.0
3+
Version: 10.6.0
44
Summary: More routines for operating on iterables, beyond itertools
55
Keywords: itertools,iterator,iteration,filter,peek,peekable,chunk,chunked
66
Author-email: Erik Rose <[email protected]>
7-
Requires-Python: >=3.8
7+
Requires-Python: >=3.9
88
Description-Content-Type: text/x-rst
99
Classifier: Development Status :: 5 - Production/Stable
1010
Classifier: Intended Audience :: Developers
1111
Classifier: Natural Language :: English
1212
Classifier: License :: OSI Approved :: MIT License
1313
Classifier: Programming Language :: Python :: 3
14-
Classifier: Programming Language :: Python :: 3.8
1514
Classifier: Programming Language :: Python :: 3.9
1615
Classifier: Programming Language :: Python :: 3.10
1716
Classifier: Programming Language :: Python :: 3.11
1817
Classifier: Programming Language :: Python :: 3.12
18+
Classifier: Programming Language :: Python :: 3.13
1919
Classifier: Programming Language :: Python :: 3 :: Only
2020
Classifier: Programming Language :: Python :: Implementation :: CPython
2121
Classifier: Programming Language :: Python :: Implementation :: PyPy
2222
Classifier: Topic :: Software Development :: Libraries
23+
Project-URL: Documentation, https://more-itertools.readthedocs.io/en/stable/
2324
Project-URL: Homepage, https://github.com/more-itertools/more-itertools
2425

2526
==============
@@ -142,6 +143,8 @@ Python iterables.
142143
| | `convolve <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.convolve>`_, |
143144
| | `dotproduct <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.dotproduct>`_, |
144145
| | `factor <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.factor>`_, |
146+
| | `is_prime <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.is_prime>`_, |
147+
| | `nth_prime <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.nth_prime>`_, |
145148
| | `matmul <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.matmul>`_, |
146149
| | `polynomial_from_roots <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.polynomial_from_roots>`_, |
147150
| | `polynomial_derivative <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.polynomial_derivative>`_, |
@@ -185,6 +188,7 @@ Python iterables.
185188
| | `numeric_range <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.numeric_range>`_, |
186189
| | `side_effect <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.side_effect>`_, |
187190
| | `iterate <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.iterate>`_, |
191+
| | `loops <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.loops>`_, |
188192
| | `difference <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.difference>`_, |
189193
| | `make_decorator <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.make_decorator>`_, |
190194
| | `SequenceView <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.SequenceView>`_, |

contrib/python/more-itertools/py3/README.rst

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ Python iterables.
118118
| | `convolve <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.convolve>`_, |
119119
| | `dotproduct <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.dotproduct>`_, |
120120
| | `factor <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.factor>`_, |
121+
| | `is_prime <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.is_prime>`_, |
122+
| | `nth_prime <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.nth_prime>`_, |
121123
| | `matmul <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.matmul>`_, |
122124
| | `polynomial_from_roots <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.polynomial_from_roots>`_, |
123125
| | `polynomial_derivative <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.polynomial_derivative>`_, |
@@ -161,6 +163,7 @@ Python iterables.
161163
| | `numeric_range <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.numeric_range>`_, |
162164
| | `side_effect <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.side_effect>`_, |
163165
| | `iterate <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.iterate>`_, |
166+
| | `loops <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.loops>`_, |
164167
| | `difference <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.difference>`_, |
165168
| | `make_decorator <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.make_decorator>`_, |
166169
| | `SequenceView <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.SequenceView>`_, |

contrib/python/more-itertools/py3/more_itertools/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
from .more import * # noqa
44
from .recipes import * # noqa
55

6-
__version__ = '10.5.0'
6+
__version__ = '10.6.0'

contrib/python/more-itertools/py3/more_itertools/more.py

+63-45
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from math import comb, e, exp, factorial, floor, fsum, log, log1p, perm, tau
2626
from queue import Empty, Queue
2727
from random import random, randrange, shuffle, uniform
28-
from operator import itemgetter, mul, sub, gt, lt, le
28+
from operator import itemgetter, mul, sub, gt, lt
2929
from sys import hexversion, maxsize
3030
from time import monotonic
3131

@@ -35,7 +35,9 @@
3535
UnequalIterablesError,
3636
consume,
3737
flatten,
38+
nth,
3839
powerset,
40+
sieve,
3941
take,
4042
unique_everseen,
4143
all_equal,
@@ -104,6 +106,7 @@
104106
'minmax',
105107
'nth_or_last',
106108
'nth_permutation',
109+
'nth_prime',
107110
'nth_product',
108111
'nth_combination_with_replacement',
109112
'numeric_range',
@@ -215,8 +218,8 @@ def first(iterable, default=_marker):
215218
return item
216219
if default is _marker:
217220
raise ValueError(
218-
'first() was called on an empty iterable, and no '
219-
'default value was provided.'
221+
'first() was called on an empty iterable, '
222+
'and no default value was provided.'
220223
)
221224
return default
222225

@@ -237,15 +240,14 @@ def last(iterable, default=_marker):
237240
if isinstance(iterable, Sequence):
238241
return iterable[-1]
239242
# Work around https://bugs.python.org/issue38525
240-
elif hasattr(iterable, '__reversed__') and (hexversion != 0x030800F0):
243+
if hasattr(iterable, '__reversed__'):
241244
return next(reversed(iterable))
242-
else:
243-
return deque(iterable, maxlen=1)[-1]
245+
return deque(iterable, maxlen=1)[-1]
244246
except (IndexError, TypeError, StopIteration):
245247
if default is _marker:
246248
raise ValueError(
247-
'last() was called on an empty iterable, and no default was '
248-
'provided.'
249+
'last() was called on an empty iterable, '
250+
'and no default value was provided.'
249251
)
250252
return default
251253

@@ -569,8 +571,8 @@ def one(iterable, too_short=None, too_long=None):
569571
pass
570572
else:
571573
msg = (
572-
'Expected exactly one item in iterable, but got {!r}, {!r}, '
573-
'and perhaps more.'.format(first_value, second_value)
574+
f'Expected exactly one item in iterable, but got {first_value!r}, '
575+
f'{second_value!r}, and perhaps more.'
574576
)
575577
raise too_long or ValueError(msg)
576578

@@ -631,13 +633,13 @@ def strictly_n(iterable, n, too_short=None, too_long=None):
631633
if too_short is None:
632634
too_short = lambda item_count: raise_(
633635
ValueError,
634-
'Too few items in iterable (got {})'.format(item_count),
636+
f'Too few items in iterable (got {item_count})',
635637
)
636638

637639
if too_long is None:
638640
too_long = lambda item_count: raise_(
639641
ValueError,
640-
'Too many items in iterable (got at least {})'.format(item_count),
642+
f'Too many items in iterable (got at least {item_count})',
641643
)
642644

643645
it = iter(iterable)
@@ -1118,10 +1120,8 @@ def spy(iterable, n=1):
11181120
[1, 2, 3, 4, 5]
11191121
11201122
"""
1121-
it = iter(iterable)
1122-
head = take(n, it)
1123-
1124-
return head.copy(), chain(head, it)
1123+
p, q = tee(iterable)
1124+
return take(n, q), p
11251125

11261126

11271127
def interleave(*iterables):
@@ -1558,8 +1558,8 @@ def split_into(iterable, sizes):
15581558
[[1], [2, 3], [4], []]
15591559
15601560
When a ``None`` object is encountered in *sizes*, the returned list will
1561-
contain items up to the end of *iterable* the same way that itertools.slice
1562-
does:
1561+
contain items up to the end of *iterable* the same way that
1562+
:func:`itertools.slice` does:
15631563
15641564
>>> list(split_into([1,2,3,4,5,6,7,8,9,0], [2,3,None]))
15651565
[[1, 2], [3, 4, 5], [6, 7, 8, 9, 0]]
@@ -2167,13 +2167,11 @@ def __init__(self, *args):
21672167
self._start, self._stop, self._step = args
21682168
elif argc == 0:
21692169
raise TypeError(
2170-
'numeric_range expected at least '
2171-
'1 argument, got {}'.format(argc)
2170+
f'numeric_range expected at least 1 argument, got {argc}'
21722171
)
21732172
else:
21742173
raise TypeError(
2175-
'numeric_range expected at most '
2176-
'3 arguments, got {}'.format(argc)
2174+
f'numeric_range expected at most 3 arguments, got {argc}'
21772175
)
21782176

21792177
self._zero = type(self._step)(0)
@@ -2236,7 +2234,7 @@ def __getitem__(self, key):
22362234
else:
22372235
raise TypeError(
22382236
'numeric range indices must be '
2239-
'integers or slices, not {}'.format(type(key).__name__)
2237+
f'integers or slices, not {type(key).__name__}'
22402238
)
22412239

22422240
def __hash__(self):
@@ -2277,13 +2275,10 @@ def __reduce__(self):
22772275

22782276
def __repr__(self):
22792277
if self._step == 1:
2280-
return "numeric_range({}, {})".format(
2281-
repr(self._start), repr(self._stop)
2282-
)
2283-
else:
2284-
return "numeric_range({}, {}, {})".format(
2285-
repr(self._start), repr(self._stop), repr(self._step)
2286-
)
2278+
return f"numeric_range({self._start!r}, {self._stop!r})"
2279+
return (
2280+
f"numeric_range({self._start!r}, {self._stop!r}, {self._step!r})"
2281+
)
22872282

22882283
def __reversed__(self):
22892284
return iter(
@@ -2307,7 +2302,7 @@ def index(self, value):
23072302
if r == self._zero:
23082303
return int(q)
23092304

2310-
raise ValueError("{} is not in numeric range".format(value))
2305+
raise ValueError(f"{value} is not in numeric range")
23112306

23122307
def _get_by_index(self, i):
23132308
if i < 0:
@@ -2781,7 +2776,7 @@ def __len__(self):
27812776
return len(self._target)
27822777

27832778
def __repr__(self):
2784-
return '{}({})'.format(self.__class__.__name__, repr(self._target))
2779+
return f'{self.__class__.__name__}({self._target!r})'
27852780

27862781

27872782
class seekable:
@@ -3443,8 +3438,8 @@ def only(iterable, default=None, too_long=None):
34433438
pass
34443439
else:
34453440
msg = (
3446-
'Expected exactly one item in iterable, but got {!r}, {!r}, '
3447-
'and perhaps more.'.format(first_value, second_value)
3441+
f'Expected exactly one item in iterable, but got {first_value!r}, '
3442+
f'{second_value!r}, and perhaps more.'
34483443
)
34493444
raise too_long or ValueError(msg)
34503445

@@ -3726,9 +3721,11 @@ def feed(i):
37263721
reservoir = []
37273722
for _ in range(k):
37283723
reservoir.append(feed(0))
3729-
if strict and len(reservoir) < k:
3730-
raise ValueError('Sample larger than population')
37313724

3725+
if strict and len(reservoir) < k:
3726+
raise ValueError('Sample larger than population')
3727+
3728+
with suppress(StopIteration):
37323729
W = 1.0
37333730
while True:
37343731
W *= exp(log(random()) / k)
@@ -3821,15 +3818,16 @@ def is_sorted(iterable, key=None, reverse=False, strict=False):
38213818
38223819
The function returns ``False`` after encountering the first out-of-order
38233820
item, which means it may produce results that differ from the built-in
3824-
:func:`sorted` function for objects with unusual comparison dynamics.
3825-
If there are no out-of-order items, the iterable is exhausted.
3821+
:func:`sorted` function for objects with unusual comparison dynamics
3822+
(like ``math.nan``). If there are no out-of-order items, the iterable is
3823+
exhausted.
38263824
"""
3827-
compare = le if strict else lt
38283825
it = iterable if (key is None) else map(key, iterable)
3829-
it_1, it_2 = tee(it)
3830-
next(it_2 if reverse else it_1, None)
3831-
3832-
return not any(map(compare, it_1, it_2))
3826+
a, b = tee(it)
3827+
next(b, None)
3828+
if reverse:
3829+
b, a = a, b
3830+
return all(map(lt, a, b)) if strict else not any(map(lt, b, a))
38333831

38343832

38353833
class AbortThread(BaseException):
@@ -4822,8 +4820,8 @@ def outer_product(func, xs, ys, *args, **kwargs):
48224820
48234821
>>> xs = ['A', 'B', 'A', 'A', 'B', 'B', 'A', 'A', 'B', 'B']
48244822
>>> ys = ['X', 'X', 'X', 'Y', 'Z', 'Z', 'Y', 'Y', 'Z', 'Z']
4825-
>>> rows = list(zip(xs, ys))
4826-
>>> count_rows = lambda x, y: rows.count((x, y))
4823+
>>> pair_counts = Counter(zip(xs, ys))
4824+
>>> count_rows = lambda x, y: pair_counts[x, y]
48274825
>>> list(outer_product(count_rows, sorted(set(xs)), sorted(set(ys))))
48284826
[(2, 3, 0), (1, 0, 4)]
48294827
@@ -4978,3 +4976,23 @@ def doublestarmap(func, iterable):
49784976
"""
49794977
for item in iterable:
49804978
yield func(**item)
4979+
4980+
4981+
def _nth_prime_ub(n):
4982+
"Upper bound for the nth prime (counting from 1)."
4983+
# https://en.wikipedia.org/wiki/Prime-counting_function#Inequalities
4984+
return n * log(n * log(n)) if n >= 6 else 11.1
4985+
4986+
4987+
def nth_prime(n):
4988+
"""Return the nth prime (counting from 0).
4989+
4990+
>>> nth_prime(0)
4991+
2
4992+
>>> nth_prime(100)
4993+
547
4994+
"""
4995+
if n < 0:
4996+
raise ValueError
4997+
limit = math.ceil(_nth_prime_ub(n + 1))
4998+
return nth(sieve(limit), n)

0 commit comments

Comments
 (0)