API: preprocessing.split
skyulf.preprocessing.split
Train/test/val splitter and feature/target splitter nodes.
These nodes return a :class:SplitDataset (not the canonical (X, y) shape),
so they cannot use :func:apply_dual_engine — the dispatcher expects appliers
that return (X_out, y_out). Instead, we centralise the engine handling in
two small helpers:
- :func:
_to_pandas_remember_engineconverts to pandas and records whether a conversion happened. - :func:
_back_to_engineconverts the result back to polars when needed.
This removes the inline if engine.name == EngineName.POLARS branches from
both :class:DataSplitter methods and :class:FeatureTargetSplitApplier.
DataSplitter
Split a DataFrame (or X/y pair) into Train, Test, and optional Validation.
Source code in skyulf-core/skyulf/preprocessing/split.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 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 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | |
__init__(test_size=0.2, validation_size=0.0, random_state=DEFAULT_RANDOM_STATE, shuffle=True, stratify_col=None)
Validate and store the split proportions and stratification column.
stratify_col names the column to balance class proportions on;
None disables stratification. random_state and shuffle are
reused for both the test carve and the validation carve, so the
partitioning is reproducible as a whole.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in skyulf-core/skyulf/preprocessing/split.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
split(df, *, sample_weight=None)
Split a whole frame row-wise, leaving any target column in place.
Shares :meth:split_xy's engine handling. Stratification here reads
stratify_col out of the frame itself, so a configured column that is
absent from df disables stratification with a warning instead of
raising.
Source code in skyulf-core/skyulf/preprocessing/split.py
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 388 389 390 391 392 393 | |
split_indices(n, stratify=None, *, groups=None)
Split row positions for an initial train/test or calibration partition.
Callers gather features, targets and weights with these same positions.
Optional groups remain whole; group splits require shuffle and cannot
simultaneously stratify. This method does not create a third validation
partition; split and split_xy own that optional second split.
Source code in skyulf-core/skyulf/preprocessing/split.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
split_xy(X, y, *, sample_weight=None)
Split an (X, y) pair into train/test and optional validation.
Polars input is partitioned by index gather and never converted; other engines round-trip through pandas and are converted back, so the result stays on the input engine. Requested stratification is downgraded to an unstratified split, with a warning, when the rarest class has fewer than two members.
Source code in skyulf-core/skyulf/preprocessing/split.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
FeatureTargetSplitApplier
Bases: BaseApplier
Separate the target column from the features without moving any rows.
Source code in skyulf-core/skyulf/preprocessing/split.py
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 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |
apply(df, params)
Return (X, y) with target_column lifted out of the features.
A SplitDataset has each train/test/validation member split on its
own, and members that already are (X, y) pairs pass through
untouched; a bare tuple is returned as-is.
Raises:
| Type | Description |
|---|---|
ValueError
|
If no |
Source code in skyulf-core/skyulf/preprocessing/split.py
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 658 659 660 661 662 | |
inference_capability(state, *, engine)
staticmethod
Describe native pair extraction; pipelines omit this training-only marker.
Source code in skyulf-core/skyulf/preprocessing/split.py
617 618 619 620 621 622 623 | |
validate_inference_state(raw)
staticmethod
Inspect the saved target name without executing feature/target extraction.
Source code in skyulf-core/skyulf/preprocessing/split.py
609 610 611 612 613 614 615 | |
FeatureTargetSplitCalculator
Bases: BaseCalculator
Carry the configured target column into the artifact.
Source code in skyulf-core/skyulf/preprocessing/split.py
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 | |
fit(df, config)
Return a typed artifact holding target_column as a string.
The key is omitted entirely when unconfigured or None, which is what
makes the applier raise rather than split on an empty name.
Source code in skyulf-core/skyulf/preprocessing/split.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 | |
infer_output_schema(input_schema, config)
Return input_schema, target column included, so pickers can still select it.
Source code in skyulf-core/skyulf/preprocessing/split.py
694 695 696 697 698 699 700 701 702 703 704 705 | |
SplitApplier
Bases: BaseApplier
Route the input to the right :class:DataSplitter entry point.
Source code in skyulf-core/skyulf/preprocessing/split.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
apply(df, params, *, sample_weight=None)
Split df into train/test and optional validation.
Routes three ways: an (X, y) tuple is split as a pair; a plain frame
carrying a configured target_column has that column lifted into y
first; anything else is split row-wise with the target left in place.
Source code in skyulf-core/skyulf/preprocessing/split.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
SplitCalculator
Bases: BaseCalculator
Carry the split configuration into the artifact; splitting happens at apply time.
Source code in skyulf-core/skyulf/preprocessing/split.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
fit(df, config)
Return a typed artifact and warn about ignored public configuration keys.
type and underscore-prefixed routing metadata are ignored quietly.
Use stratify=True with target_column to request stratification;
stratify_col belongs to DataSplitter, not this node's config.
Source code in skyulf-core/skyulf/preprocessing/split.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
infer_output_schema(input_schema, config)
Return input_schema: every split frame keeps the full column set.
Source code in skyulf-core/skyulf/preprocessing/split.py
237 238 239 240 241 242 243 244 245 | |