API: preprocessing.casting
skyulf.preprocessing.casting
Type-casting node — routes apply through the dual-engine dispatcher.
The fit step resolves configuration and freezes categorical vocabularies.
The pandas apply path was previously a single CCN-busting function; it is now
split per dtype family (float / int / bool / datetime / other).
CastingApplier
Bases: BaseApplier
Cast each column named in type_map to its target dtype on the active engine.
coerce_on_error=True (the default) is best-effort per column: the pandas
path swallows any cast failure and leaves that column untouched, the polars
path casts with strict=False. With it off, both engines raise. The
awkward families are hand-written on each path because the native casts
disagree — polars truncates fractional floats where pandas masks them, and
pandas' astype clamps out-of-range integers where polars nulls or raises.
Boolean targets additionally go through the shared alias table so
"yes"/"no"-style strings coerce the same way on both engines in best-effort
mode, including Polars Categorical and Enum labels. Text-to-datetime casts
share the pandas mixed-format parser and retain the resolved engine dtype.
Columns missing from the frame are skipped. New categorical artifacts
freeze the training vocabulary; unseen values become missing. Older
artifacts without a vocabulary retain their original casting behavior.
Source code in skyulf-core/skyulf/preprocessing/casting.py
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
apply(X, _y, params)
Dispatch through the mapping-keyed dual-engine path; y passes through.
Source code in skyulf-core/skyulf/preprocessing/casting.py
633 634 635 636 637 638 | |
inference_capability(state, *, engine)
staticmethod
Describe local casts, including request-derived legacy pandas vocabularies.
Source code in skyulf-core/skyulf/preprocessing/casting.py
624 625 626 627 628 629 630 631 | |
validate_inference_state(raw)
staticmethod
Inspect local dtype/vocabulary state without converting or relearning it.
Source code in skyulf-core/skyulf/preprocessing/casting.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 | |
CastingCalculator
Bases: BaseCalculator
Normalise either accepted config shape into one canonical type_map.
Ordinary casts resolve dtype aliases through TYPE_ALIASES. Category
casts additionally learn the observed training vocabulary so applying a
held-out batch cannot change the accepted categories or pandas codes.
Source code in skyulf-core/skyulf/preprocessing/casting.py
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 | |
fit(X, _y, config)
Merge the two config shapes into a type_map of columns present on X.
Absent columns are dropped rather than erroring, so a config written
against a wider frame degrades to a partial cast; when both shapes name
the same column, target_type overwrites the column_types entry.
Source code in skyulf-core/skyulf/preprocessing/casting.py
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
infer_output_schema(input_schema, config)
Rewrite the dtype labels of input_schema for every column the config targets.
The shared target_type overrides per-column choices, matching fit.
Columns absent from the input schema are skipped, as they are at runtime.
Source code in skyulf-core/skyulf/preprocessing/casting.py
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 | |