flpit 0.4.0.dev2__py3-none-any.whl → 0.4.0.dev6__py3-none-any.whl
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/core/linq.py +20 -3
- flpit/csv.py +543 -87
- flpit/json/__init__.py +168 -0
- flpit/json/_core.py +418 -0
- flpit/{json.py → json/_msgspec.py} +164 -245
- flpit/json/_native.py +1076 -0
- {flpit-0.4.0.dev2.dist-info → flpit-0.4.0.dev6.dist-info}/METADATA +42 -5
- {flpit-0.4.0.dev2.dist-info → flpit-0.4.0.dev6.dist-info}/RECORD +10 -7
- {flpit-0.4.0.dev2.dist-info → flpit-0.4.0.dev6.dist-info}/WHEEL +0 -0
- {flpit-0.4.0.dev2.dist-info → flpit-0.4.0.dev6.dist-info}/licenses/LICENSE +0 -0
flpit/core/linq.py
CHANGED
|
@@ -15,6 +15,7 @@ from itertools import islice, chain, compress
|
|
|
15
15
|
from numbers import Real as _Real
|
|
16
16
|
|
|
17
17
|
from typing import (
|
|
18
|
+
TYPE_CHECKING,
|
|
18
19
|
Any,
|
|
19
20
|
Callable,
|
|
20
21
|
Iterable,
|
|
@@ -35,7 +36,9 @@ from typing import (
|
|
|
35
36
|
Sized
|
|
36
37
|
)
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
if TYPE_CHECKING:
|
|
40
|
+
# imported lazily at runtime: JSON support must not be loaded for plain LINQ use
|
|
41
|
+
from flpit.json import JsonSerializerOptions
|
|
39
42
|
from flpit import ZipTuple
|
|
40
43
|
from flpit.core._join import JoinTuple
|
|
41
44
|
from flpit.core._index import IndexTuple
|
|
@@ -290,8 +293,9 @@ def dotnet_context() -> AbstractContextManager[decimal.Context]:
|
|
|
290
293
|
# 1. Create and configure pure Context object
|
|
291
294
|
ctx = decimal.getcontext().copy()
|
|
292
295
|
ctx.prec = max(ctx.prec, 29)
|
|
296
|
+
ctx.Emax = ctx.prec - 1
|
|
293
297
|
ctx.traps[Overflow] = True
|
|
294
|
-
ctx.traps[Inexact] =
|
|
298
|
+
ctx.traps[Inexact] = False
|
|
295
299
|
|
|
296
300
|
return decimal.localcontext(ctx)
|
|
297
301
|
|
|
@@ -1314,12 +1318,17 @@ class FlpIt[TItem](Iterable[TItem]):
|
|
|
1314
1318
|
else:
|
|
1315
1319
|
try:
|
|
1316
1320
|
total += item
|
|
1317
|
-
except
|
|
1321
|
+
except Overflow:
|
|
1318
1322
|
raise OverflowError(
|
|
1319
1323
|
"System.OverflowException: Value was either too large or too small for a Decimal."
|
|
1320
1324
|
)
|
|
1321
1325
|
count += 1
|
|
1322
1326
|
|
|
1327
|
+
if isinstance(total, Decimal) and total.adjusted() >= decimal.getcontext().prec:
|
|
1328
|
+
raise OverflowError(
|
|
1329
|
+
"System.OverflowException: Value was either too large or too small for a Decimal."
|
|
1330
|
+
)
|
|
1331
|
+
|
|
1323
1332
|
return total, count
|
|
1324
1333
|
|
|
1325
1334
|
|
|
@@ -1504,14 +1513,17 @@ class FlpIt[TItem](Iterable[TItem]):
|
|
|
1504
1513
|
|
|
1505
1514
|
@classmethod
|
|
1506
1515
|
def from_json[T](cls, data: str | bytes, item_type: type[T], jso: JsonSerializerOptions|None=None) -> FlpIt[T]:
|
|
1516
|
+
from flpit.json import JsonConvert
|
|
1507
1517
|
return FlpIt[T](JsonConvert.deserialize(data, list[item_type], jso))
|
|
1508
1518
|
|
|
1509
1519
|
def to_json_bytes[T](self, item_type: type[T], jso: JsonSerializerOptions|None=None) -> bytes:
|
|
1520
|
+
from flpit.json import JsonConvert
|
|
1510
1521
|
writer = BytesIO()
|
|
1511
1522
|
JsonConvert.serialize_to(self, item_type, writer, jso)
|
|
1512
1523
|
return writer.getvalue()
|
|
1513
1524
|
|
|
1514
1525
|
def to_json[T](self, item_type: type[T], jso: JsonSerializerOptions|None=None) -> str:
|
|
1526
|
+
from flpit.json import JsonConvert
|
|
1515
1527
|
writer = StringIO()
|
|
1516
1528
|
JsonConvert.serialize_to(self, item_type, writer, jso)
|
|
1517
1529
|
return writer.getvalue()
|
|
@@ -1522,6 +1534,7 @@ class FlpIt[TItem](Iterable[TItem]):
|
|
|
1522
1534
|
output: BinaryIO,
|
|
1523
1535
|
jso: JsonSerializerOptions | None = None,
|
|
1524
1536
|
) -> None:
|
|
1537
|
+
from flpit.json import JsonConvert
|
|
1525
1538
|
JsonConvert.serialize_to(self, item_type, output, jso)
|
|
1526
1539
|
|
|
1527
1540
|
|
|
@@ -2315,12 +2328,15 @@ class FlpList[TItem](Collection[TItem]):
|
|
|
2315
2328
|
|
|
2316
2329
|
@classmethod
|
|
2317
2330
|
def from_json[T](cls, data: str | bytes, item_type: type[T], jso: JsonSerializerOptions|None=None) -> FlpList[T]:
|
|
2331
|
+
from flpit.json import JsonConvert
|
|
2318
2332
|
return FlpList[T](JsonConvert.deserialize(data, list[item_type], jso))
|
|
2319
2333
|
|
|
2320
2334
|
def to_json_bytes[T](self, item_type: type[T], jso: JsonSerializerOptions|None=None) -> bytes:
|
|
2335
|
+
from flpit.json import JsonConvert
|
|
2321
2336
|
return JsonConvert.serialize_bytes(self.__list.data, list[item_type], jso)
|
|
2322
2337
|
|
|
2323
2338
|
def to_json[T](self, item_type: type[T], jso: JsonSerializerOptions|None=None) -> str:
|
|
2339
|
+
from flpit.json import JsonConvert
|
|
2324
2340
|
return JsonConvert.serialize(self.__list.data, list[item_type], jso)
|
|
2325
2341
|
|
|
2326
2342
|
def write_json[T](
|
|
@@ -2329,6 +2345,7 @@ class FlpList[TItem](Collection[TItem]):
|
|
|
2329
2345
|
output: BinaryIO,
|
|
2330
2346
|
jso: JsonSerializerOptions | None = None,
|
|
2331
2347
|
) -> None:
|
|
2348
|
+
from flpit.json import JsonConvert
|
|
2332
2349
|
JsonConvert.serialize_to(self, item_type, output, jso)
|
|
2333
2350
|
|
|
2334
2351
|
# I hate it, but Python being Python
|