|
82 | 82 | ft.FLOAT: 4, |
83 | 83 | ft.DOUBLE: 8, |
84 | 84 | } |
| 85 | +medium_int_types = set([ft.INT24, -ft.INT24]) |
85 | 86 | int_types = set([ |
86 | 87 | ft.TINY, -ft.TINY, ft.SHORT, -ft.SHORT, ft.INT24, -ft.INT24, |
87 | 88 | ft.LONG, -ft.LONG, ft.LONGLONG, -ft.LONGLONG, |
@@ -369,6 +370,16 @@ def _dump( |
369 | 370 | out.write(struct.pack(numeric_formats[rtype], default)) |
370 | 371 | else: |
371 | 372 | if rtype in int_types: |
| 373 | + if rtype == ft.INT24: |
| 374 | + if int(value) > 8388607 or int(value) < -8388608: |
| 375 | + raise ValueError( |
| 376 | + 'value is outside range of MEDIUMINT', |
| 377 | + ) |
| 378 | + elif rtype == -ft.INT24: |
| 379 | + if int(value) > 16777215 or int(value) < 0: |
| 380 | + raise ValueError( |
| 381 | + 'value is outside range of UNSIGNED MEDIUMINT', |
| 382 | + ) |
372 | 383 | out.write(struct.pack(numeric_formats[rtype], int(value))) |
373 | 384 | else: |
374 | 385 | out.write(struct.pack(numeric_formats[rtype], float(value))) |
@@ -437,6 +448,16 @@ def _dump_vectors( |
437 | 448 | out.write(struct.pack(numeric_formats[rtype], default)) |
438 | 449 | else: |
439 | 450 | if rtype in int_types: |
| 451 | + if rtype == ft.INT24: |
| 452 | + if int(value) > 8388607 or int(value) < -8388608: |
| 453 | + raise ValueError( |
| 454 | + 'value is outside range of MEDIUMINT', |
| 455 | + ) |
| 456 | + elif rtype == -ft.INT24: |
| 457 | + if int(value) > 16777215 or int(value) < 0: |
| 458 | + raise ValueError( |
| 459 | + 'value is outside range of UNSIGNED MEDIUMINT', |
| 460 | + ) |
440 | 461 | out.write(struct.pack(numeric_formats[rtype], int(value))) |
441 | 462 | else: |
442 | 463 | out.write(struct.pack(numeric_formats[rtype], float(value))) |
@@ -697,18 +718,16 @@ def _dump_arrow_accel( |
697 | 718 |
|
698 | 719 |
|
699 | 720 | if not has_accel: |
700 | | - _load_accel = _load |
701 | | - _dump_accel = _dump |
702 | | - load = _load |
703 | | - dump = _dump |
704 | | - load_pandas = _load_pandas |
705 | | - dump_pandas = _dump_pandas |
706 | | - load_numpy = _load_numpy |
707 | | - dump_numpy = _dump_numpy |
708 | | - load_arrow = _load_arrow |
709 | | - dump_arrow = _dump_arrow |
710 | | - load_polars = _load_polars |
711 | | - dump_polars = _dump_polars |
| 721 | + load = _load_accel = _load |
| 722 | + dump = _dump_accel = _dump |
| 723 | + load_pandas = _load_pandas_accel = _load_pandas # noqa: F811 |
| 724 | + dump_pandas = _dump_pandas_accel = _dump_pandas # noqa: F811 |
| 725 | + load_numpy = _load_numpy_accel = _load_numpy # noqa: F811 |
| 726 | + dump_numpy = _dump_numpy_accel = _dump_numpy # noqa: F811 |
| 727 | + load_arrow = _load_arrow_accel = _load_arrow # noqa: F811 |
| 728 | + dump_arrow = _dump_arrow_accel = _dump_arrow # noqa: F811 |
| 729 | + load_polars = _load_polars_accel = _load_polars # noqa: F811 |
| 730 | + dump_polars = _dump_polars_accel = _dump_polars # noqa: F811 |
712 | 731 |
|
713 | 732 | else: |
714 | 733 | _load_accel = _singlestoredb_accel.load_rowdat_1 |
|
0 commit comments