flpit 0.3.2__tar.gz → 0.3.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flpit-0.3.2 → flpit-0.3.4}/PKG-INFO +1 -1
- {flpit-0.3.2 → flpit-0.3.4}/pyproject.toml +1 -1
- {flpit-0.3.2 → flpit-0.3.4}/src/flpit/core/linq.py +32 -14
- {flpit-0.3.2 → flpit-0.3.4}/.gitignore +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/LICENSE +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/README.md +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/src/flp/__init__.py +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/src/flpit/__init__.py +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/src/flpit/core/__init__.py +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/src/flpit/core/_grouping.py +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/src/flpit/core/_index.py +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/src/flpit/core/_join.py +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/src/flpit/core/_lookup.py +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/src/flpit/core/_zip.py +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/src/flpit/csv.py +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/src/flpit/flp.py +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/src/flpit/json.py +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/src/flpit/py.typed +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/src/flpit/task.py +0 -0
- {flpit-0.3.2 → flpit-0.3.4}/src/flpit/threading.py +0 -0
|
@@ -290,12 +290,26 @@ def dotnet_context() -> AbstractContextManager[decimal.Context]:
|
|
|
290
290
|
# 1. Create and configure pure Context object
|
|
291
291
|
ctx = decimal.getcontext().copy()
|
|
292
292
|
ctx.prec = max(ctx.prec, 29)
|
|
293
|
+
ctx.Emax = ctx.prec - 1
|
|
293
294
|
ctx.traps[Overflow] = True
|
|
294
|
-
ctx.traps[Inexact] =
|
|
295
|
+
ctx.traps[Inexact] = False
|
|
295
296
|
|
|
296
297
|
return decimal.localcontext(ctx)
|
|
297
298
|
|
|
298
299
|
|
|
300
|
+
def _decimal_mean(total: Decimal, count: int) -> Decimal:
|
|
301
|
+
"""
|
|
302
|
+
``total / count`` like .NET ``decimal`` division: rounded to 29 significant digits instead of
|
|
303
|
+
raising ``Inexact`` (the summation context traps ``Inexact`` only to detect decimal overflow).
|
|
304
|
+
"""
|
|
305
|
+
ctx = decimal.getcontext().copy()
|
|
306
|
+
ctx.prec = max(ctx.prec, 29)
|
|
307
|
+
ctx.traps[Inexact] = False
|
|
308
|
+
ctx.traps[Overflow] = True
|
|
309
|
+
with decimal.localcontext(ctx):
|
|
310
|
+
return total / Decimal(count)
|
|
311
|
+
|
|
312
|
+
|
|
299
313
|
class _FactoryIterable[TItem](Iterable[TItem]):
|
|
300
314
|
"""
|
|
301
315
|
Wraps a generator factory function into a clean Iterable[T].
|
|
@@ -929,20 +943,18 @@ class FlpIt[TItem](Iterable[TItem]):
|
|
|
929
943
|
|
|
930
944
|
Produces everything ``left_join`` does (unmatched outer elements paired with ``None``),
|
|
931
945
|
followed by every inner element that was never matched by any outer element, paired with
|
|
932
|
-
``None`` as the outer element (``result_selector(None, inner)``), in
|
|
946
|
+
``None`` as the outer element (``result_selector(None, inner)``), grouped by key in order of
|
|
947
|
+
first key appearance (like .NET, which walks its inner lookup).
|
|
933
948
|
Elements with a ``None`` key never match and therefore always appear unmatched.
|
|
934
949
|
The outer sequence is streamed; the inner sequence is buffered.
|
|
935
950
|
"""
|
|
936
951
|
_validate_join_args(inner, outer_key_selector, inner_key_selector, result_selector)
|
|
937
952
|
|
|
938
953
|
def _generator() -> Iterator[Any]:
|
|
939
|
-
|
|
954
|
+
# Like .NET (Lookup.Create): None keys are kept, but never match.
|
|
940
955
|
lookup: dict[Any, list[TInner]] = {}
|
|
941
956
|
for inner_item in inner:
|
|
942
|
-
|
|
943
|
-
inner_items.append((inner_key, inner_item))
|
|
944
|
-
if inner_key is not None:
|
|
945
|
-
lookup.setdefault(inner_key, []).append(inner_item)
|
|
957
|
+
lookup.setdefault(inner_key_selector(inner_item), []).append(inner_item)
|
|
946
958
|
|
|
947
959
|
matched_keys: set[Any] = set()
|
|
948
960
|
for outer_item in self:
|
|
@@ -961,12 +973,13 @@ class FlpIt[TItem](Iterable[TItem]):
|
|
|
961
973
|
else:
|
|
962
974
|
yield result_selector(outer_item, inner_item)
|
|
963
975
|
|
|
964
|
-
for inner_key,
|
|
976
|
+
for inner_key, group in lookup.items():
|
|
965
977
|
if inner_key is None or inner_key not in matched_keys:
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
978
|
+
for inner_item in group:
|
|
979
|
+
if result_selector is _SENTINEL:
|
|
980
|
+
yield JoinTuple(None, inner_item)
|
|
981
|
+
else:
|
|
982
|
+
yield result_selector(None, inner_item)
|
|
970
983
|
|
|
971
984
|
return FlpIt(_FactoryIterable(_generator))
|
|
972
985
|
|
|
@@ -1265,7 +1278,7 @@ class FlpIt[TItem](Iterable[TItem]):
|
|
|
1265
1278
|
return None
|
|
1266
1279
|
|
|
1267
1280
|
if isinstance(total, Decimal):
|
|
1268
|
-
return total
|
|
1281
|
+
return _decimal_mean(total, count)
|
|
1269
1282
|
|
|
1270
1283
|
assert total is not None
|
|
1271
1284
|
assert isinstance(total, Decimal) or isinstance(total, int) or isinstance(total, float)
|
|
@@ -1302,12 +1315,17 @@ class FlpIt[TItem](Iterable[TItem]):
|
|
|
1302
1315
|
else:
|
|
1303
1316
|
try:
|
|
1304
1317
|
total += item
|
|
1305
|
-
except
|
|
1318
|
+
except Overflow:
|
|
1306
1319
|
raise OverflowError(
|
|
1307
1320
|
"System.OverflowException: Value was either too large or too small for a Decimal."
|
|
1308
1321
|
)
|
|
1309
1322
|
count += 1
|
|
1310
1323
|
|
|
1324
|
+
if isinstance(total, Decimal) and total.adjusted() >= decimal.getcontext().prec:
|
|
1325
|
+
raise OverflowError(
|
|
1326
|
+
"System.OverflowException: Value was either too large or too small for a Decimal."
|
|
1327
|
+
)
|
|
1328
|
+
|
|
1311
1329
|
return total, count
|
|
1312
1330
|
|
|
1313
1331
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|