flpit 0.3.2__tar.gz → 0.3.3__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.3}/PKG-INFO +1 -1
- {flpit-0.3.2 → flpit-0.3.3}/pyproject.toml +1 -1
- {flpit-0.3.2 → flpit-0.3.3}/src/flpit/core/linq.py +24 -12
- {flpit-0.3.2 → flpit-0.3.3}/.gitignore +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/LICENSE +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/README.md +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/src/flp/__init__.py +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/src/flpit/__init__.py +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/src/flpit/core/__init__.py +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/src/flpit/core/_grouping.py +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/src/flpit/core/_index.py +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/src/flpit/core/_join.py +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/src/flpit/core/_lookup.py +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/src/flpit/core/_zip.py +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/src/flpit/csv.py +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/src/flpit/flp.py +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/src/flpit/json.py +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/src/flpit/py.typed +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/src/flpit/task.py +0 -0
- {flpit-0.3.2 → flpit-0.3.3}/src/flpit/threading.py +0 -0
|
@@ -296,6 +296,19 @@ def dotnet_context() -> AbstractContextManager[decimal.Context]:
|
|
|
296
296
|
return decimal.localcontext(ctx)
|
|
297
297
|
|
|
298
298
|
|
|
299
|
+
def _decimal_mean(total: Decimal, count: int) -> Decimal:
|
|
300
|
+
"""
|
|
301
|
+
``total / count`` like .NET ``decimal`` division: rounded to 29 significant digits instead of
|
|
302
|
+
raising ``Inexact`` (the summation context traps ``Inexact`` only to detect decimal overflow).
|
|
303
|
+
"""
|
|
304
|
+
ctx = decimal.getcontext().copy()
|
|
305
|
+
ctx.prec = max(ctx.prec, 29)
|
|
306
|
+
ctx.traps[Inexact] = False
|
|
307
|
+
ctx.traps[Overflow] = True
|
|
308
|
+
with decimal.localcontext(ctx):
|
|
309
|
+
return total / Decimal(count)
|
|
310
|
+
|
|
311
|
+
|
|
299
312
|
class _FactoryIterable[TItem](Iterable[TItem]):
|
|
300
313
|
"""
|
|
301
314
|
Wraps a generator factory function into a clean Iterable[T].
|
|
@@ -929,20 +942,18 @@ class FlpIt[TItem](Iterable[TItem]):
|
|
|
929
942
|
|
|
930
943
|
Produces everything ``left_join`` does (unmatched outer elements paired with ``None``),
|
|
931
944
|
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
|
|
945
|
+
``None`` as the outer element (``result_selector(None, inner)``), grouped by key in order of
|
|
946
|
+
first key appearance (like .NET, which walks its inner lookup).
|
|
933
947
|
Elements with a ``None`` key never match and therefore always appear unmatched.
|
|
934
948
|
The outer sequence is streamed; the inner sequence is buffered.
|
|
935
949
|
"""
|
|
936
950
|
_validate_join_args(inner, outer_key_selector, inner_key_selector, result_selector)
|
|
937
951
|
|
|
938
952
|
def _generator() -> Iterator[Any]:
|
|
939
|
-
|
|
953
|
+
# Like .NET (Lookup.Create): None keys are kept, but never match.
|
|
940
954
|
lookup: dict[Any, list[TInner]] = {}
|
|
941
955
|
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)
|
|
956
|
+
lookup.setdefault(inner_key_selector(inner_item), []).append(inner_item)
|
|
946
957
|
|
|
947
958
|
matched_keys: set[Any] = set()
|
|
948
959
|
for outer_item in self:
|
|
@@ -961,12 +972,13 @@ class FlpIt[TItem](Iterable[TItem]):
|
|
|
961
972
|
else:
|
|
962
973
|
yield result_selector(outer_item, inner_item)
|
|
963
974
|
|
|
964
|
-
for inner_key,
|
|
975
|
+
for inner_key, group in lookup.items():
|
|
965
976
|
if inner_key is None or inner_key not in matched_keys:
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
977
|
+
for inner_item in group:
|
|
978
|
+
if result_selector is _SENTINEL:
|
|
979
|
+
yield JoinTuple(None, inner_item)
|
|
980
|
+
else:
|
|
981
|
+
yield result_selector(None, inner_item)
|
|
970
982
|
|
|
971
983
|
return FlpIt(_FactoryIterable(_generator))
|
|
972
984
|
|
|
@@ -1265,7 +1277,7 @@ class FlpIt[TItem](Iterable[TItem]):
|
|
|
1265
1277
|
return None
|
|
1266
1278
|
|
|
1267
1279
|
if isinstance(total, Decimal):
|
|
1268
|
-
return total
|
|
1280
|
+
return _decimal_mean(total, count)
|
|
1269
1281
|
|
|
1270
1282
|
assert total is not None
|
|
1271
1283
|
assert isinstance(total, Decimal) or isinstance(total, int) or isinstance(total, float)
|
|
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
|