API: preprocessing.bucketing
skyulf.preprocessing.bucketing
Binning / discretization nodes (GeneralBinning, CustomBinning, KBinsDiscretizer).
All Appliers share a single :class:BaseBinningApplier which routes through
:func:apply_dual_engine. Per-engine helpers live at module level so each one
stays at low CCN. Fits are sklearn / pandas-bound (pd.cut, pd.qcut,
KBinsDiscretizer), so they convert via to_pandas once at the top and do
not use :func:fit_dual_engine.
BaseBinningApplier
Bases: BaseApplier
Shared Applier for all binning Calculators.
Expects bin_edges in params: Dict[str, List[float]] mapping column
names to bin edges.
missing_strategy="label" fills null/NaN and out-of-range bins with
missing_label (default "Missing"). Polars emits String columns for
this mode, including complete and empty batches; ordinal/bin-index values
become "0", "1", etc. Pandas retains numeric bin values alongside
the string sentinel in an object column. Range and custom labels keep
their text. The default "keep" strategy preserves missing values.
Newly fitted range artifacts store canonical range_labels so their
category keys remain identical across engines. Exact edge text replaces
rounded labels if rounding would merge distinct bins. Older artifacts retain
their original rendering; refit binning and downstream encoders together
before moving a legacy range pipeline to another engine.
Source code in skyulf-core/skyulf/preprocessing/bucketing.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | |
apply(X, _y, params)
Dispatch through the mapping-keyed dual-engine path; y passes through.
Each entry in bin_edges gains a {col}{output_suffix} column, and
drop_original removes only the columns that were actually binned. A
column that cannot be binned (fewer than two unique edges, bad dtype) is
left unbinned rather than failing the whole frame — warned about on the
pandas path, silently skipped on the polars one.
Conflicting retained output names and labels that cannot describe
deduplicated edges raise ValueError before producing output. A
dropped source name can be reused safely, including an empty suffix.
Source code in skyulf-core/skyulf/preprocessing/bucketing.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | |
CustomBinningApplier
Bases: GeneralBinningApplier
Applier registered for the CustomBinning node id.
Empty subclass — custom edges are applied by exactly the same cut logic as fitted ones, so nothing here needs to differ.
Source code in skyulf-core/skyulf/preprocessing/bucketing.py
602 603 604 605 606 607 608 609 | |
CustomBinningCalculator
Bases: BaseCalculator
Apply user-supplied bin edges to selected columns.
Source code in skyulf-core/skyulf/preprocessing/bucketing.py
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 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
fit(X, _y, config)
Attach one shared, sorted edge list from config["bins"] to every selected column.
Edges are fixed, but automatic column selection examines observed
values to exclude binary, constant, and all-missing columns.
Unlike :class:GeneralBinningCalculator
the same edges go to every column, so a multi-column selection spanning
different scales will push the out-of-scale columns' values outside the
outer bins, where both engines null them. An empty or absent bins
leaves bin_edges empty, which makes apply a no-op.
Source code in skyulf-core/skyulf/preprocessing/bucketing.py
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
GeneralBinningApplier
Bases: BaseBinningApplier
Applier registered for the GeneralBinning node id.
Empty subclass: every binning behaviour is inherited from
:class:BaseBinningApplier. It exists as its own type so this node id
registers against a distinct Applier class, and as the base for the
CustomBinning and KBinsDiscretizer appliers.
Source code in skyulf-core/skyulf/preprocessing/bucketing.py
503 504 505 506 507 508 509 510 511 512 | |
GeneralBinningCalculator
Bases: BaseCalculator
Master calculator that handles mixed strategies and per-column overrides.
Source code in skyulf-core/skyulf/preprocessing/bucketing.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | |
fit(X, _y, config)
Fit bin edges per column under each column's own strategy.
An explicitly empty columns list short-circuits to an empty artifact
(the user unchecked everything), whereas an absent one falls through to
:func:detect_numeric_columns. Only the selected columns are converted
to pandas, since the fits are pd.cut / pd.qcut / sklearn-bound.
Columns whose strategy cannot be fit are logged and skipped rather than
failing the node, so the artifact may cover fewer columns than requested.
Source code in skyulf-core/skyulf/preprocessing/bucketing.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | |
KBinsDiscretizerApplier
Bases: GeneralBinningApplier
Applier registered for the KBinsDiscretizer node id.
Empty subclass — sklearn only picks the edges at fit time; applying them is the same cut as for any other binning node.
Source code in skyulf-core/skyulf/preprocessing/bucketing.py
660 661 662 663 664 665 666 667 | |
KBinsDiscretizerCalculator
Bases: GeneralBinningCalculator
Thin wrapper around :class:GeneralBinningCalculator with kbins strategy.
Source code in skyulf-core/skyulf/preprocessing/bucketing.py
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 | |
fit(df, config)
Translate this node's public params onto GeneralBinning's internal names, then delegate.
On a copy of config (the caller's dict is never mutated) it forces
strategy="kbins", moves n_bins to kbins_n_bins, and preserves
a user-chosen non-kbins strategy as kbins_strategy so
quantile / uniform / kmeans still reach sklearn. Written with
the raw (df, config) signature rather than @fit_method because it
only rewrites config and forwards — the parent's decorated fit does
the (X, y) unpack.
Source code in skyulf-core/skyulf/preprocessing/bucketing.py
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | |