Core¶
StudyContext¶
fleet.core.StudyContext
¶
Runtime context that resolves configured study paths.
Source code in src/fleet/core/study_context.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 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 246 247 248 249 250 251 252 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 | |
codelists_file
property
¶
Resolve the generated codelists.py path (inside SDTM metadata dir).
custom_rules_dir
property
¶
Resolve the custom validation rules directory, or None if not configured.
resolve
¶
data_dir
¶
The configured data directory of one standard ("sdtm" or "adam").
Source code in src/fleet/core/study_context.py
metadata_dir
¶
The configured metadata directory of one standard ("sdtm" or "adam").
Source code in src/fleet/core/study_context.py
init
classmethod
¶
init(
study_root,
study_id,
company=None,
protocol_name=None,
description="",
paths=None,
sdtm=None,
adam=None,
ct=None,
validation=None,
)
Scaffold a new study workspace and return a ready-to-use StudyContext.
Creates the directory layout defined by StudyPathConfig and writes
study_config.yaml. Define specs and codelists are created by
subsequent pipeline steps (fleet init define, fleet init ct).
Directories are created silently if they already exist. If
study_config.yaml already exists the method raises
StudyConfigError to protect in-progress work.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study_root
|
str | Path
|
Root directory for the study (created if absent). |
required |
study_id
|
str
|
Study identifier (e.g. |
required |
company
|
str | None
|
Optional originator / company name. |
None
|
protocol_name
|
str | None
|
Optional protocol identifier. |
None
|
description
|
str
|
Optional study description. |
''
|
paths
|
StudyPathConfig | None
|
Custom path config; defaults to |
None
|
sdtm
|
SDTMConfig | None
|
SDTM IG configuration (version, domains). |
None
|
adam
|
ADAMConfig | None
|
ADaM IG configuration (version, datasets). |
None
|
ct
|
CTConfig | None
|
CT package configuration. |
None
|
validation
|
ValidationConfig | None
|
Validation engine configuration (engine path, custom rules). |
None
|
Returns:
| Type | Description |
|---|---|
StudyContext
|
Initialized |
Raises:
| Type | Description |
|---|---|
StudyConfigError
|
If |
Source code in src/fleet/core/study_context.py
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 | |
options: show_root_heading: true heading_level: 3 filters: ["!^_"]
load_study_context¶
fleet.core.load_study_context
¶
Load study configuration and return a resolved context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
Path
|
Path to study_config.yaml |
required |
Returns:
| Type | Description |
|---|---|
StudyContext
|
StudyContext with resolved paths |
Raises:
| Type | Description |
|---|---|
StudyConfigError
|
If the config file is missing or invalid |
Source code in src/fleet/core/study_context.py
options: show_root_heading: true heading_level: 3
PipelineDAG¶
fleet.core.PipelineDAG
dataclass
¶
Directed Acyclic Graph of pipeline dataset dependencies.
Build with :func:build_dag rather than constructing directly.
Source code in src/fleet/core/dag.py
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 185 186 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 246 247 248 249 250 251 252 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 | |
execution_order
¶
Return all node names in a safe topological execution order.
Uses Kahn's algorithm (BFS on in-degree).
Raises¶
ValueError
If the graph contains a cycle (should have been caught by
:func:build_dag, but re-checked here for safety).
Source code in src/fleet/core/dag.py
impacted_by
¶
Return all nodes that must be rerun when name changes.
Performs a BFS downstream from name, then returns the results in topological execution order so callers get a ready-made run schedule.
Parameters¶
name: Logical node name (dataset or raw source) that changed.
Returns¶
list[str] Topologically-ordered list of node names to rerun, inclusive of name itself.
Raises¶
KeyError If name is not a node in this DAG.
Source code in src/fleet/core/dag.py
inject_lineage
¶
Merge variable-level and pin lineage from namespace into the DAG.
Populates variables on the node named dataset_name (when a
variable was derived more than once, the last derivation wins —
matching what the materialised frame actually contains) and, for
each PinDependency, adds the pinned source domain to the
node's inputs if it is not already present (creating the
cross-domain edge in the DAG).
Declared inputs: are reconciled against the runtime pin
evidence in both directions:
- a dataset-type input declared in the spec but never consulted
at runtime emits a
UserWarning(stale declaration); - a runtime pin source missing from the declaration emits a
UserWarningand the edge is added (the DAG follows the evidence).
Raw inputs carry no pin evidence and are exempt from the declared-but-unused check.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
Any
|
A namespace instance with |
required |
dataset_name
|
str
|
The logical node name to attach lineage to. |
required |
Source code in src/fleet/core/dag.py
trace
¶
Return the full recursive provenance chain for a single variable.
Walks the variable's sources transitively — including
cross-domain pin sources into other DAG nodes — collecting every
upstream derived variable exactly once (cycle-safe, deduped).
Raw/leaf columns appear inside each entry's sources but do
not get entries of their own.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
str
|
Logical node name (e.g. |
required |
variable
|
str
|
Column name (e.g. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict]: Depth-first provenance entries from the output
variable back to its sources, each with |
Source code in src/fleet/core/dag.py
to_dict
¶
Return a JSON-serializable adjacency representation.
Shape::
{
"dm_raw": {"node_type": "raw", "path": "datasets/.../dm_raw.csv", "inputs": []},
"DM": {"node_type": "sdtm", "path": "outputs/.../dm.parquet", "inputs": ["dm_raw"]},
"ADSL": {"node_type": "adam", "path": "outputs/.../adsl.parquet","inputs": ["DM"]},
...
}
Source code in src/fleet/core/dag.py
to_snakemake
¶
Return a Snakemake-compatible rule dict.
Each entry maps a logical name to {"input": [...paths...], "output": path}.
Drop this into a Snakefile generator to produce concrete rules::
for name, rule in dag.to_snakemake().items():
# rule["input"] → list of input file paths
# rule["output"] → output file path
Raw nodes are included with an empty input list and the source
file as output, so Snakemake can model them as source checkpoints.
Source code in src/fleet/core/dag.py
to_airflow
¶
Return an Airflow-compatible task dependency dict.
Shape::
{
"DM": [], # no upstream tasks
"ADSL": ["DM"],
"ADVS": ["VS", "ADSL"],
}
Wire operators in a DAG file with::
for task_id, upstreams in dag.to_airflow().items():
for u in upstreams:
tasks[u] >> tasks[task_id]
Source code in src/fleet/core/dag.py
generate
¶
Write the DAG to output_path as a JSON file.
The file contains the full adjacency representation produced by
:meth:to_dict plus the topological execution order, so it is
self-contained and can be consumed by external tools without needing
to re-parse the define YAMLs.
Parameters¶
output_path:
Destination path for the .json file (e.g.
outputs/cdiscpilot01/pipeline_dag.json).
Example¶
::
dag = build_dag(
"examples/cdiscpilot01/sdtm/define.yaml",
"examples/cdiscpilot01/adam/define.yaml",
output_dir="outputs/cdiscpilot01",
)
dag.generate("outputs/cdiscpilot01/pipeline_dag.json")
Source code in src/fleet/core/dag.py
options: show_root_heading: true heading_level: 3 filters: ["!^_"]
Derivation¶
fleet.core.derivation.Derivation
dataclass
¶
A registered custom derivation: callable + rich lineage metadata.
Created by the :func:derivation decorator. Instances are callable —
invoking them dispatches to the underlying function according to kind.
Attributes:
| Name | Type | Description |
|---|---|---|
fn |
Callable
|
The wrapped callable. |
name |
str
|
Function name (used as registry key). |
kind |
Literal['column', 'frame']
|
Dispatch strategy: |
targets |
list[str]
|
Output column names produced by this derivation.
For |
sources |
list[str]
|
Input column names consumed (populated automatically
for |
dotted_path |
str
|
Fully qualified import path for Define-XML MethodDef
(e.g. |
Source code in src/fleet/core/derivation.py
options: show_root_heading: true heading_level: 3 filters: ["!^_"]
derivation (decorator)¶
fleet.core.derivation.derivation
¶
Decorator that wraps a function as a typed :class:Derivation object.
Supports both bare and parameterised forms.
Bare form (kind inferred from return annotation)::
@derivation
def AGEGR1() -> pl.Expr:
return pl.when(pl.col("AGE") < 65).then(pl.lit("<65 yrs")).otherwise(pl.lit(">=65 yrs"))
A column derivation writes to the column named as the function
(AGEGR1 above). An explicit .alias() on the expression wins.
Parameterised form::
@derivation(targets=["SAFFL", "ITTFL"])
def add_pop_flags(df: pl.DataFrame) -> pl.DataFrame: ...
Kind inference rules:
+-------------------------------------------------------+-----------+
| Condition | Kind |
+=======================================================+===========+
| Return annotation is pl.Expr | column|
+-------------------------------------------------------+-----------+
| Return annotation is pl.DataFrame | frame |
+-------------------------------------------------------+-----------+
| No parameters on the function | column|
+-------------------------------------------------------+-----------+
| Otherwise | frame |
+-------------------------------------------------------+-----------+
A new parameter row (PARAMCD = "BMI") is not a derivation: use
.adam.derive_param().
After decoration the function name is auto-registered in the Fleet transform registry, making it referenceable by name in YAML specs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable | None
|
The function to decorate (bare form only; |
None
|
targets
|
list[str] | None
|
Explicit list of output column names. Inferred
automatically for |
None
|
sources
|
list[str] | None
|
Explicit list of input column names. Inferred
automatically for |
None
|
**removed
|
Any
|
|
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Derivation | Callable[[Callable], Derivation]
|
class: |
Derivation | Callable[[Callable], Derivation]
|
one (parameterised form). |
Raises:
| Type | Description |
|---|---|
VerbUsageError
|
When |
Source code in src/fleet/core/derivation.py
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 246 247 248 249 250 251 252 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 | |
options: show_root_heading: true heading_level: 3
to_repr¶
fleet.core.repr_utils.to_repr
¶
Return a pl.from_repr()-ingestible table string for df.
Temporarily adjusts Polars display settings so that wide tables and long strings are never truncated, then restores original settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame | LazyFrame
|
A Polars DataFrame or LazyFrame to render. |
required |
max_cols
|
int
|
Maximum number of columns to display (avoids |
50
|
max_width
|
int
|
Maximum character width for the table. |
500
|
max_str_len
|
int
|
Maximum string length before truncation. |
100
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A Unicode box-drawing table string that can be pasted directly
into |
Examples:
Generate a pasteable repr and use it to recreate the DataFrame::
import polars as pl
from fleet import to_repr
# Start with any DataFrame (e.g. from a CSV, query, or dict)
original = pl.DataFrame({
"USUBJID": ["S001", "S002"],
"AGE": [35, 42],
"ARM": ["Drug A", "Placebo"],
})
# Generate the from_repr-ready string
print(to_repr(original))
# shape: (2, 3)
# ┌─────────┬─────┬─────────┐
# │ USUBJID ┆ AGE ┆ ARM │
# │ --- ┆ --- ┆ --- │
# │ str ┆ i64 ┆ str │
# ╞═════════╪═════╪═════════╡
# │ S001 ┆ 35 ┆ Drug A │
# │ S002 ┆ 42 ┆ Placebo │
# └─────────┴─────┴─────────┘
# Paste that output into pl.from_repr() in your test/example:
df = pl.from_repr("""\
┌─────────┬─────┬─────────┐
│ USUBJID ┆ AGE ┆ ARM │
│ --- ┆ --- ┆ --- │
│ str ┆ i64 ┆ str │
╞═════════╪═════╪═════════╡
│ S001 ┆ 35 ┆ Drug A │
│ S002 ┆ 42 ┆ Placebo │
└─────────┴─────┴─────────┘
""")
assert df.shape == (2, 3)
Source code in src/fleet/core/repr_utils.py
options: show_root_heading: true heading_level: 3
SharedVerbsMixin¶
Verbs available on every namespace (df.sdtm, df.adam, df.adam.adsl, …).
fleet.core._verb_mixin.SharedVerbsMixin
¶
Base mixin providing verbs shared across SDTM and ADaM namespaces.
Concrete namespace classes must provide
_lazy: pl.LazyFrameinstance attribute (set in__init__)
Class-level constants for parameterised verbs
_STUDY_DAY_REF_COL: default reference date column (e.g."RFSTDTC"or"TRTSDT")_STUDY_DAY_REF_PIN: default pinned domain name (e.g."DM"or"ADSL")_SEQ_DEFAULT_GROUPS: default grouping columns forseq()_VALIDATE_STANDARD:"sdtm"or"adam"
Source code in src/fleet/core/_verb_mixin.py
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 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 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 639 640 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 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 | |
last_validation
property
¶
The most recent ValidationResult produced by validate().
None when validate() has not run on this chain. Use it
to gate CI on validation outcomes without breaking the fluent
chain::
ns = df.sdtm.assign("DOMAIN", value="DM").validate("DM")
assert ns.last_validation is not None
assert ns.last_validation.is_valid
last_comparison
property
¶
The most recent comparison report produced by compare().
None when compare() has not run on this chain. Use it to
gate a script on the comparison outcome without breaking the
fluent chain::
ns = qc_df.adam.source("USUBJID").compare(adsl_prod, keys="USUBJID")
assert ns.last_comparison is not None
assert ns.last_comparison.is_equal, ns.last_comparison.raised_flags
last_nodup_report
property
¶
Duplicate rows found by the most recent nodup() call.
A pl.DataFrame containing every row that participated in a
duplicate key group (empty frame when no duplicates were found),
or None when nodup() has not run on this chain. Makes
report-only audits programmatically reachable::
ns = df.sdtm.nodup(subset=["USUBJID", "AESEQ"])
dups = ns.last_nodup_report
assert dups is not None and dups.height == 0
to_frame
¶
Materialise the accumulated pipeline into a Polars DataFrame.
Returns:
| Name | Type | Description |
|---|---|---|
DataFrame |
DataFrame
|
The fully materialised result of all chained
verbs — a plain |
Raises:
| Type | Description |
|---|---|
DerivationError
|
When collection fails because a column is
missing — enriched with the lineage entries that
reference the column, so the error names the verb(s)
involved. Also when a |
Examples:
Collect the pipeline result::
result = (
df.sdtm
.assign("DOMAIN", value="DM")
.assign("USUBJID", source="subject_id")
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
to_dataset_json
¶
Materialise the pipeline and write a CDISC Dataset-JSON v1.1 file.
This is a terminal verb — it collects the lazy plan and writes the
result. No further chaining is possible after this call. After
:meth:from_spec on a define.yaml, the file gets the define labels,
lengths, key sequence and OIDs of the dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Destination file path (should end in |
required |
domain
|
str
|
Dataset / domain name (e.g. |
required |
label
|
str | None
|
Optional human-readable dataset label; it wins over the define label. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
Path to the written file. |
Raises:
| Type | Description |
|---|---|
DerivationError
|
When a foreign-key check fails under
|
Examples:
Export a dataset to Dataset-JSON::
path = (
df.sdtm
.assign("DOMAIN", value="DM")
.assign("USUBJID", source="subject_id")
.to_dataset_json("outputs/dm.json", domain="DM")
)
Source code in src/fleet/core/_verb_mixin.py
inspect
¶
Materialise the pipeline at this point and log its state.
Creates a hard checkpoint: the pipeline resumes from the
materialised frame, making it easy to isolate exactly where a
derivation goes wrong. Output goes through the "fleet"
logger (INFO level, stdout by default — see
:mod:fleet.core.log).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Label logged alongside the diagnostic output. |
'DEBUG'
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
A fresh namespace wrapping the materialised frame;
call further verbs or |
Examples:
Inspect the pipeline after assigning key variables::
result = (
df.sdtm
.assign("DOMAIN", value="DM")
.inspect(prefix="After DOMAIN")
.assign("USUBJID", source="subject_id")
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
explain
¶
Log the current Polars query plan without materialising.
Useful for understanding how Polars will optimise the accumulated
derivation pipeline. Output goes through the "fleet" logger
(INFO level, stdout by default — see :mod:fleet.core.log).
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The same namespace instance (unchanged); call
further verbs or |
Examples:
Log the query plan before collecting::
result = (
df.sdtm
.assign("DOMAIN", value="DM")
.explain()
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
trail
¶
Log a table of each derived variable's origin in the pipeline.
Renders the accumulated variable lineage — the verb that produced
each column and the source columns it consumed, including
cross-domain pin sources — as a table through the "fleet"
logger (INFO level, stdout by default — see
:mod:fleet.core.log), then returns the namespace unchanged so
the chain continues. Unlike inspect, nothing is
materialised: the trail is pure metadata captured automatically on
every verb call.
Only derived variables appear; columns that pass through untouched
from the source frame are not listed. When a variable is derived more
than once, each derivation is shown in pipeline order. Variables with
no source column (e.g. hardcoded constants) are marked (literal).
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The same namespace instance (unchanged); call further
verbs or |
Examples:
Print the origin of every derived variable before collecting::
ae = (
ae_raw.sdtm
.assign("USUBJID", source="patient_number")
.assign("AESTDTC", source="ae_start_date")
.pin("DM", dm)
.study_day("AESTDY", date_col="AESTDTC")
.trail()
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
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 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 | |
write_parquet
¶
Materialise the pipeline, write to Parquet, and return the DataFrame.
This is a drop-in alternative to to_frame() when you want to
persist the dataset as part of the chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Destination file path. |
required |
mkdir
|
bool
|
When |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
DataFrame |
DataFrame
|
The materialised result (typed as
:class: |
Examples:
Write a domain to Parquet::
dm = (
raw_df.sdtm
.assign("USUBJID", source="patient_number")
.write_parquet("outputs/dm.parquet")
)
Source code in src/fleet/core/_verb_mixin.py
assign
¶
assign(
target,
*,
source=None,
value=None,
ct=None,
ct_map=None,
ct_validator=None,
validate_values=None
)
Assign target from a source column or a literal value.
The one canonical assignment verb. Exactly one of source / value must be given; controlled-terminology behaviour is toggled by the presence of ct / ct_map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
Name of the output variable to create. |
required |
source
|
str | None
|
Input column to copy from. Mutually exclusive with value. |
None
|
value
|
Any | None
|
Literal value to broadcast to every row. Mutually exclusive with source. |
None
|
ct
|
str | type | None
|
CDISC CT codelist for validation — a generated codelist
class (e.g. |
None
|
ct_map
|
dict[str, str] | None
|
Explicit |
None
|
ct_validator
|
CTValidator | None
|
Optional pre-built validator instance. |
None
|
validate_values
|
bool | None
|
Controls the codelist check of the values the
column will hold (after ct_map). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace with target appended; call
|
Raises:
| Type | Description |
|---|---|
DerivationError
|
When neither or both of source / value are given. |
VerbUsageError
|
When ct_map is combined with value. |
Examples:
Copy, hardcode, and CT-map in one vocabulary::
dm = (
raw_df.sdtm
.assign("USUBJID", source="subject_id")
.assign("DOMAIN", value="DM")
.assign("SEX", source="sex", ct=SEX,
ct_map={"1": "M", "2": "F"})
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
case_when
¶
Multi-branch conditional derivation (first matching branch wins).
The one canonical conditional verb.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
Name of the output variable. |
required |
when
|
list[dict[str, Any]]
|
Ordered list of |
required |
else_
|
Any
|
Fallback value when no branch matches. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace with target appended; call
|
Examples:
Derive an age group::
adsl = (
dm_df.adam.adsl
.case_when("AGEGR1", when=[
{"condition": 'pl.col("AGE") < 65', "value": "<65"},
{"condition": 'pl.col("AGE") < 75', "value": "65-74"},
], else_=">=75")
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
merge
¶
Join dataset into the pipeline using key column(s) on.
The one canonical join verb. The join is appended to the lazy
plan; nothing is materialised. It reads as SAS
merge left right(keep=...): every pipeline column stays, and
keep limits the columns taken from dataset. Keys match
exactly: "S1 " and "S1" are two keys.
A non-key column on both sides raises: select or rename the
columns of dataset first. A key that repeats on both sides
warns at to_frame(), because the join then gives every pair
of rows. how="full" gives one key column, as SAS MERGE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DataFrame | LazyFrame | None
|
The |
None
|
on
|
str | list[str] | None
|
Key column name(s) for the join. |
None
|
how
|
str
|
Join strategy (default |
'left'
|
keep
|
list[str] | None
|
Optional columns of dataset to bring in, besides the
on key(s). When |
None
|
where
|
str | Expr | None
|
Optional filter expression applied to dataset before the join; it may use a column that keep leaves out. |
None
|
validate
|
Literal['m:1', '1:m', '1:1'] | None
|
Optional key rule, checked at |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace continuing from the joined plan. |
Raises:
| Type | Description |
|---|---|
VerbUsageError
|
When dataset or on is missing. |
DerivationError
|
When a keep entry is absent from dataset
(with a did-you-mean suggestion), or a non-key column is on
both sides. At |
References
ADR-0032 (docs/adr/0032-merge-reads-as-sas-merge-and-stops-on-a-clash.md).
admiral derive_vars_merged stops on a column on both sides.
Examples:
Merge one supplemental qualifier onto the DM domain::
dm = (
raw_df.sdtm
.assign("DOMAIN", value="DM")
.merge(
suppdm_df,
on="USUBJID",
keep=["QVAL"],
where='pl.col("QNAM") == "RACE1"',
validate="m:1",
)
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 | |
keep
¶
Restrict the frame to columns, in the given order.
Accepts either variadic names — keep("STUDYID", "USUBJID") —
or a single list — keep(["STUDYID", "USUBJID"]). Stays lazy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*columns
|
str | list[str]
|
Column names (or one list of names) to keep. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace continuing from the restricted plan. |
Raises:
| Type | Description |
|---|---|
DerivationError
|
When a requested column is absent (with a did-you-mean suggestion), or no columns are given. |
Examples:
Keep only the submission variables::
dm = (
raw_df.sdtm
.assign("USUBJID", source="subject_id")
.keep("STUDYID", "USUBJID", "SEX")
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
verbs
¶
List the public verbs available on this namespace.
Walks the class MRO collecting public Fleet-defined methods and
returns a tidy frame with each verb's name, the first sentence
of its docstring and the namespace that defines it. This is
the always-current alternative to hard-coded verb counts in
docs, and the discovery seam for a sub-namespace: autocomplete
shows every inherited verb, origin tells them apart.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: Columns |
Examples:
Discover what an SDTM pipeline can do::
import fleet # noqa: F401
catalog = raw_df.sdtm.verbs()
print(catalog)
Keep only the verbs a therapeutic-area namespace adds::
own = raw_df.adam.metabolic.verbs().filter(
pl.col("origin") == "adam.metabolic"
)
Source code in src/fleet/core/_verb_mixin.py
derivation
¶
Derive target using an expression, lambda, or Derivation object.
Four call forms are supported:
Case 1 — string (AST-sandboxed, YAML-compatible)::
.derivation("COL", expression="pl.col('src').cast(pl.String)")
Case 2 — direct pl.Expr::
.derivation("COL", expression=pl.col("src").cast(pl.String))
Case 3 — zero-arg lambda returning pl.Expr (full IDE support)::
.derivation("COL", expression=lambda: pl.col("src").cast(pl.Int32))
Case 4 — @derivation object (file-based, full lineage)::
from specs.study01.derivations import MY_DRULE
.derivation(MY_DRULE)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str | Derivation | None
|
For Cases 1–3, the name of the output variable
(required). For Case 4, the
:class: |
None
|
expression
|
str | Expr | Callable[[], Expr] | None
|
A Polars expression, expression string, or zero-arg
callable returning |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace with target appended; call |
Raises:
| Type | Description |
|---|---|
ValueError
|
If target is a string but expression is not provided, or vice-versa. |
TypeError
|
If a lambda-style expression does not return
|
Examples:
Case 1 — string expression::
result = (
raw_df.sdtm
.derivation("SITEID", expression="pl.col('site_id').cast(pl.String)")
.to_frame()
)
Case 3 — lambda::
result = (
raw_df.sdtm
.derivation("VISITNUM", expression=lambda: pl.col("visit").cast(pl.Int32))
.to_frame()
)
Case 4 — @derivation object::
from specs.study01.derivations import MY_DRULE
result = (
raw_df.sdtm
.derivation(MY_DRULE)
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 | |
duration
¶
Compute the duration between two date/datetime columns.
Supports column references (str) and Polars expressions
for start and end; an expression is read by its type, as a
column is. --DTC text is read by its date part for
day-based units and by its date-time for hours, minutes and
seconds; a partial value gives null, and for hours, minutes and
seconds a warning gives the count of text values with no time.
The add_one parameter controls inclusive counting:
None(default): auto-resolves from the target suffix and the unit.*DYtargets in days use the CDISC study-day convention (no day 0). Days, weeks, months and years add one day before the division; hours, minutes and seconds give the raw difference (PK elapsed time).True: add one day (day-based units) or one unit (sub-day).False: raw difference.
One is added only when the end is on or after the start, as
admiral compute_duration does: an end one day before the start
gives -1, never 0. Weeks, months and years divide the day count
by 7, 30.4375 and 365.25, so this verb does not give a completed
age in years.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
Name of the output column. |
required |
start
|
str | Expr
|
Start date column name or expression. |
required |
end
|
str | Expr
|
End date column name or expression. |
required |
unit
|
Literal['seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years']
|
Duration unit — |
'days'
|
add_one
|
bool | None
|
Override for inclusive counting. |
None
|
out
|
Literal['numeric', 'iso8601']
|
Output format — |
'numeric'
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace with target appended; call |
Raises:
| Type | Description |
|---|---|
DerivationError
|
On an unknown unit/out value, when
|
References
ISO 8601 durations and SDTMIG 3.4 --ELTM; admiral
compute_duration; ADR-0011 and ADR-0022.
Examples:
ISO 8601 duration::
ex = (
raw_df.sdtm
.date("EXSTDTC", source="dose_start")
.date("EXENDTC", source="dose_end")
.duration("EXDUR", start="EXSTDTC", end="EXENDTC",
out="iso8601")
.to_frame()
)
Treatment duration in days::
adsl = (
dm_df.adam.adsl
.duration("TRTDURD", start="TRTSDT", end="TRTEDT")
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 | |
study_day
¶
Derive a CDISC study day variable from a date column and reference date.
Uses the CDISC algorithm: date - ref_date + 1 when
date >= ref_date, else date - ref_date (no day 0), on the
date portion of each value (SDTMIG 3.4 section 4.4.4): a time
part is ignored, and a partial date gives null.
The reference date is resolved in this order:
- Explicit
ref_df=parameter (highest priority).dm=andadsl=are accepted aliases ofref_df=matching the SDTM/ADaM vocabulary. - Pinned domain (via
.pin(...)). ref_colalready present in the current frame.- Actionable
LookupError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
Name of the output study day variable
(e.g. |
required |
date_col
|
str
|
Column containing the date to measure from. |
required |
ref_col
|
str | None
|
Reference date column name. Defaults to
|
None
|
ref_pin
|
str | None
|
Pinned domain name. Defaults to
|
None
|
ref_df
|
DataFrame | None
|
Optional explicit DataFrame override — bypasses pinning. |
None
|
dm
|
DataFrame | None
|
Alias of ref_df (SDTM vocabulary). |
None
|
adsl
|
DataFrame | None
|
Alias of ref_df (ADaM vocabulary). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace with target appended; call
|
Raises:
| Type | Description |
|---|---|
LookupError
|
If the reference date cannot be resolved from any source. |
VerbUsageError
|
If more than one of ref_df / dm / adsl is given. |
DerivationError
|
If the reference frame has two different reference dates for one subject (ADR-0032). |
Examples:
Derive study day from pinned reference::
ae = (
ae_raw.sdtm
.pin("DM", dm_df)
.study_day("AESTDY", date_col="AESTDTC")
.to_frame()
)
ADaM study day::
adae = (
ae_df.adam.occds("ADAE")
.pin("ADSL", adsl_df)
.study_day("ASTDY", date_col="ASTDT")
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 | |
seq
¶
Derive a 1-based sequence number within each group.
Generates a 1-based integer sequence that uniquely identifies each record within a grouping partition. The dataset is sorted by order_by columns within each by partition before numbering — ensuring deterministic, reproducible sequence values. The sort and the window numbering are appended to the lazy plan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
Name of the output sequence variable (e.g. |
'ASEQ'
|
order_by
|
list[str] | None
|
Columns that define the sort order within each group.
Records that tie keep their input order, as PROC SORT
EQUALS. When |
None
|
by
|
list[str] | None
|
Partition columns. Defaults to class constant
|
None
|
start_at
|
int
|
First sequence value (default |
1
|
check_uniqueness
|
bool
|
If |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
A fresh namespace with target appended; call
|
Examples:
SDTM sequence number::
ae = (
raw_df.sdtm
.seq("AESEQ", order_by=["AESTDTC"])
.to_frame()
)
ADaM sequence number::
adae = (
ae_df.adam.occds
.seq("ASEQ", order_by=["ASTDT"], by=["USUBJID"])
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 | |
validate
¶
validate(
dataset_or_domain,
version=None,
rules_engine_path=None,
custom_rules=None,
report="smart",
on_fail="warn",
)
Run CDISC conformance validation and report the findings.
Returns a namespace copy so the chain can continue after
validation; the full :class:~fleet.validation.models.ValidationResult
is retrievable via the :attr:last_validation property. The
report is emitted through the "fleet.validation" logger
(stdout by default — see :mod:fleet.core.log).
Every input comes from a run setup
(:func:fleet.validation.run_setup.build_run_setup): an explicit
argument, then the study config found from the working directory,
then FLEET_RULES_ENGINE (engine only), then the built-in
default (SDTMIG 3.4, ADaMIG 1.3). The namespace gives the
standard. The report header prints each input with its source.
Issues are cross-linked to the chain's own variable lineage, so a
finding on a column this pipeline derived also reports the verb
that produced it (see
:func:fleet.validation.lineage_join.enrich_with_lineage).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_or_domain
|
str
|
Domain code (SDTM: e.g. |
required |
version
|
str | None
|
IG version, |
None
|
rules_engine_path
|
Path | None
|
Engine executable. Defaults to
|
None
|
custom_rules
|
str | Path | None
|
Directory of custom rule YAML files, passed to
the engine via |
None
|
report
|
Literal['smart', 'summary', 'full']
|
Report detail level — |
'smart'
|
on_fail
|
Literal['warn', 'raise', 'ignore']
|
What to do when a finding blocks (every CORE finding
that |
'warn'
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
A namespace copy carrying the result in
|
Raises:
| Type | Description |
|---|---|
ValidationSetupError
|
The validation could not run, in every
on_fail mode: the dataset name belongs to the other
standard ( |
ValidationError
|
When a finding blocks and
|
DerivationError
|
On an invalid on_fail value. |
Examples:
Validate an SDTM domain::
dm = (
raw_df.sdtm
.assign("DOMAIN", value="DM")
.validate("DM")
.to_frame()
)
Gate a CI pipeline on the ADaM validation outcome::
adsl = (
dm_df.adam.adsl
.validate("ADSL", on_fail="raise")
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 | |
compare
¶
compare(
base,
*,
keys,
by=None,
pairs=None,
variables=None,
abs_tol=0.0,
rel_tol=0.0,
ignore_trailing_whitespace=False,
blank_is_missing=False,
allow_duplicates=False,
max_print=50,
base_name=None,
candidate_name=None,
on_fail="warn"
)
Compare the chain against a base dataset, PROC COMPARE style.
The chain is the candidate and base is the reference it is
measured against. The chain is materialised, paired with the base
on keys through :func:fleet.compare, and the report is printed
through the "fleet.comparison" logger (stdout by default — see
:mod:fleet.core.log). Differences never stop the chain by
default: the verb returns a namespace copy carrying the
:class:~fleet.comparison.ComparisonReport as
:attr:last_comparison, so the pipeline continues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
DataFrame | LazyFrame
|
The reference dataset, as a DataFrame or LazyFrame. |
required |
keys
|
str | Sequence[str]
|
Variable(s) that identify one observation on each side. Required; the compare refuses to run when a key is missing or not unique on either side. |
required |
by
|
str | Sequence[str] | None
|
Variable(s) the report is sectioned by. They are prepended
to keys automatically, label the listing's |
None
|
pairs
|
Mapping[str, str] | None
|
Base variable names mapped to the names the chain gives them, on top of the automatic name matching, so a renamed column is compared rather than reported missing. The report names a paired variable by its base name. |
None
|
variables
|
str | Sequence[str] | None
|
Restrict the comparison to these variables, in base names, so a work-in-progress chain is checked on the columns that are finished. What is outside the restriction is neither compared nor reported as missing. |
None
|
abs_tol
|
float
|
Absolute tolerance on the numeric variables; |
0.0
|
rel_tol
|
float
|
Relative tolerance on the numeric variables, as a
fraction of the base value; |
0.0
|
ignore_trailing_whitespace
|
bool
|
Strip trailing whitespace from both sides of a string before comparing, so a legacy SAS dataset's padded values equal the chain's stripped ones. Leading whitespace still differs. |
False
|
blank_is_missing
|
bool
|
Read an empty string as null on both sides, keys included, as SAS does. Off by default. |
False
|
allow_duplicates
|
bool
|
Pair duplicate keys by their position within
each key group instead of refusing to run; the report then
counts them, raises |
False
|
max_print
|
MaxPrint
|
Print limits for the text report (differences per
variable, a |
50
|
base_name
|
str | None
|
Label for the base in the report, when known. |
None
|
candidate_name
|
str | None
|
Label for the chain in the report, when known. |
None
|
on_fail
|
Literal['warn', 'raise', 'ignore']
|
What to do when the datasets differ — |
'warn'
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
A namespace copy carrying the report in
|
Raises:
| Type | Description |
|---|---|
ComparisonError
|
When the datasets differ and
|
DerivationError
|
On an invalid on_fail value. |
Examples:
Prove an independently programmed ADAE matches its base, and keep chaining::
adae_qc = (
ae_df.adam.occds
.source("USUBJID")
.source("AESEQ")
.compare(adae_prod, keys=["USUBJID", "AESEQ"])
.to_frame()
)
Gate a CI script on the comparison outcome::
adsl = (
dm_df.adam.adsl
.source("USUBJID")
.compare(adsl_prod, keys="USUBJID", on_fail="raise")
.to_frame()
)
Absorb the engine noise of a legacy SAS dataset without hiding a real difference::
advs = (
vs_df.adam
.source("USUBJID")
.compare(
advs_legacy,
keys=["USUBJID", "PARAMCD", "AVISITN"],
rel_tol=1e-9,
ignore_trailing_whitespace=True,
)
.to_frame()
)
Section the comparison by treatment arm, so a difference in one arm stands out::
adsl = (
dm_df.adam.adsl
.source("USUBJID")
.compare(adsl_prod, keys="USUBJID", by="TRT01P")
.to_frame()
)
Check a work-in-progress chain on the variables that are finished, one of which the base names differently::
advs = (
vs_df.adam
.source("USUBJID")
.compare(
advs_prod,
keys=["USUBJID", "PARAMCD"],
pairs={"AVAL": "RESULT"},
variables=["AVAL", "AVISIT"],
)
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 | |
select
¶
Select and reorder columns (lazily — nothing is materialised).
Resolution order:
spec+dataset: derive the ordered column list from adefine.yaml. Only columns present in the frame are kept.columns: explicit list to keep (in that order).- Neither: keep all current columns (subject to
drop_pattern).
With a spec on an ADaM namespace, a text column the define types
date becomes the date part of a complete date, and one typed
datetime the date-time of a value with hours and minutes.
Anything else becomes null, with one warning at collect: select
never imputes. SDTM columns and every *DTC stay text, because
--DTC is character (SDTMIG 3.4 section 4.4).
drop_pattern (default r"^_"): regex applied before the
explicit selection — columns whose names match are removed. This
enforces the convention that _-prefixed columns are scratch
variables. Set to None to disable (e.g. during debugging).
A scratch name listed in columns is removed too, unless
drop_pattern=None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
str | list[str] | None
|
Explicit list of columns to keep (in order). A single string is one column name. |
None
|
spec
|
str | Path | None
|
Path to a |
None
|
dataset
|
str | None
|
Dataset name within the spec. |
None
|
drop_pattern
|
str | None
|
Regex for columns to auto-drop. |
'^_'
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
A fresh namespace continuing from the selected plan. |
Raises:
| Type | Description |
|---|---|
DerivationError
|
When a name in columns is not in the frame (with a did-you-mean suggestion). |
Examples:
Keep only spec columns::
dm = (
raw_df.sdtm
.select(spec="specs/sdtm/define.yaml", dataset="DM")
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 | |
from_spec
¶
Build a derivation pipeline from a YAML specification file.
Reads either a define.yaml (top-level datasets list where
each variable carries a derivation block) or a simplified
single-dataset spec (top-level variables list). Every
algorithm: is resolved through the central spec registry
(:mod:fleet.core.spec_registry), validated against its strict
per-algorithm model, and executed via the matching namespace verb.
A top-level ct: block opts the spec into controlled-terminology
validation::
ct:
validate: true
file: ct/cdisc_ct.yaml # optional — loaded into the CT cache
With validate: true every assign that has a codelist
(ct:, or the variable's codelist:) runs with
validate_values=True: out-of-codelist values emit the
standard warning naming dataset, variable, and codelist.
A derivation block is the verb call: algorithm: is the verb
name and the keys are its keyword arguments (ADR-0008). An
assign without ct: on a variable with codelist: checks
its values against that codelist.
Inside a study, a ct: ID resolves to the class of
that ID in the study's generated codelists.py (found from the
first study_config.yaml above the spec's folder), so a spec
step checks the same terms as assign(..., ct=<class>); an ID
the file lacks falls back to the CT loaded in
:func:fleet.get_validator. A codelists.py that disagrees
with the study warns once per process (see
:mod:fleet.ct.study_codelists).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec_path
|
str | Path
|
Path to the YAML specification file. |
required |
dataset
|
str | None
|
Dataset to execute from a multi-dataset define.yaml
(e.g. |
None
|
only
|
list[str] | None
|
Optional allow-list — process only these variable names. |
None
|
omit
|
list[str] | None
|
Optional deny-list — skip these variable names; useful to override a spec variable with custom inline logic. Mutually exclusive with only. |
None
|
strict
|
bool
|
When |
True
|
overwrite
|
bool
|
When |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
A namespace pre-loaded with all spec-driven derivations;
call |
Raises:
| Type | Description |
|---|---|
SpecError
|
On unknown algorithms (strict mode), invalid or
misspelled derivation fields, column overwrites, unknown
|
ValueError
|
When both only and omit are given, or when dataset is required/unknown. |
Examples:
Build and materialise the DM domain from a spec::
dm = (
raw_df.sdtm
.from_spec("examples/cdiscpilot01/sdtm/define.yaml", dataset="DM")
.to_frame()
)
Keep an inline derivation for one variable::
adsl = (
dm_df.adam
.from_spec("define.yaml", dataset="ADSL", omit=["TRTSDT"])
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 | |
to_spec_yaml
¶
Serialise the pipeline's lineage into a define.yaml spec.
The natural prototype-then-freeze workflow: build the dataset
inline, then emit the equivalent derivation: blocks instead
of retyping them. Variables are emitted in frame column order:
derived variables carry their derivation: block (last
derivation wins when a target was re-derived); CDISC-named
carry-through columns are listed as metadata-only entries; raw
columns that violate the CDISC name pattern are skipped. Verbs
covered by the spec registry emit real blocks; verbs that are
not spec-expressible (or whose arguments cannot be serialised,
e.g. inline Polars expressions) emit an algorithm: derivation
stub with a callable: placeholder and a # TODO comment carrying the verb name and
sources, and a warning names them. A column that a verb added
with no lineage node (merge) also gets a stub. Auto-generated
by-product columns (e.g. --DTF imputation flags) are listed
without a derivation.
A verb that removes or adds rows (whereclauses, nodup with
keep=, derive_param) goes to the dataset key
row_steps:, in pipeline order, each step anchored after:
the variable it follows (ADR-0034). A step a define.yaml cannot
hold is written as algorithm: TODO and from_spec refuses
it until it is edited.
The output validates against Fleet's define-spec JSON schema; study-level fields are placeholders to review before use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
str | None
|
Dataset name for the emitted spec. Defaults to the
pipeline's domain context (set by |
None
|
path
|
str | Path | None
|
Optional file path — when given, the YAML is also written there (parent directories are created). |
None
|
predecessor
|
str | None
|
Name of the upstream dataset this ADaM pipeline
was built from (e.g. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The define.yaml document. |
Examples:
Freeze an inline DM prototype to a spec::
ns = (
raw_df.sdtm
.assign("DOMAIN", value="DM")
.assign("USUBJID", source="subject_id")
)
yaml_text = ns.to_spec_yaml(dataset="DM", path="specs/define_dm.yaml")
dm = raw_df.sdtm.from_spec("specs/define_dm.yaml", dataset="DM").to_frame()
Freeze an ADSL prototype, labelling DM carry-throughs::
adsl_ns.to_spec_yaml(dataset="ADSL", predecessor="DM")
Source code in src/fleet/core/_verb_mixin.py
2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 | |
nodup
¶
Detect duplicate rows and optionally deduplicate after sorting.
Materialises the pipeline, logs duplicate diagnostics through the
"fleet" logger (stdout by default — see :mod:fleet.core.log),
and optionally removes duplicates. When keep is None
(default) the verb operates in report-only mode — duplicates are
reported but the frame is returned unchanged, making it safe to
insert anywhere in a pipeline for auditing purposes. The
duplicate rows are also attached to the returned namespace and
retrievable via :attr:last_nodup_report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subset
|
list[str]
|
Column(s) that define the uniqueness key. |
required |
sort_by
|
list[str] | None
|
Column(s) to sort by before deduplication. Required
when |
None
|
keep
|
Literal['first', 'last'] | None
|
Which duplicate to retain after sorting:
|
None
|
descending
|
bool | list[bool]
|
Sort direction(s) for sort_by. A single |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
A fresh namespace wrapping the (optionally deduplicated)
frame, carrying the duplicates in |
Raises:
| Type | Description |
|---|---|
DerivationError
|
If |
References
SAS PROC SORT with EQUALS and NODUPKEY; ADR-0023 for the place of a missing value.
Examples:
Report-only mode (audit duplicates without removing)::
ae = (
raw_df.sdtm
.assign("USUBJID", source="subject_id")
.nodup(subset=["USUBJID", "AEDECOD", "AESTDTC"])
.to_frame()
)
Sort and deduplicate (keep latest record)::
adae = (
ae_df.adam.occds
.nodup(
subset=["USUBJID", "AEDECOD"],
sort_by=["ASTDT", "ASEQ"],
keep="first",
descending=True,
)
.to_frame()
)
Source code in src/fleet/core/_verb_mixin.py
2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 | |
options: show_root_heading: false heading_level: 3 members_order: source filters: ["!^_"]
Exceptions¶
fleet.core.exceptions
¶
Core exceptions for fleet.
The verb-layer exceptions use dual inheritance so both catch styles
work: except FleetError (the Fleet-native style) and the legacy
builtin style (except ValueError / except TypeError /
except LookupError) that predates the hierarchy.
- :class:
DerivationError— a verb received invalid values or arguments (missing column, unparseable expression, unsupported option, ...). Catchable asValueError. - :class:
VerbUsageError— a verb was called with a wrong type. Catchable asTypeError. - :class:
PinError— a cross-domain verb could not resolve a pinned reference domain. Catchable asLookupError.
FleetError
¶
DerivationError
¶
Bases: FleetError, ValueError
Raised when a derivation verb receives invalid values or arguments.
Dual-inherits from ValueError so legacy except ValueError
handlers keep working.
VerbUsageError
¶
Bases: FleetError, TypeError
Raised when a verb is called with arguments of the wrong type.
Dual-inherits from TypeError so legacy except TypeError
handlers keep working.
PinError
¶
Bases: FleetError, LookupError
Raised when a pinned reference domain cannot be resolved.
Dual-inherits from LookupError so legacy except LookupError
handlers keep working.
SDTMError
¶
Bases: FleetError
Raised when SDTM namespace operations fail.
ADAMError
¶
Bases: FleetError
Raised when ADaM namespace operations fail.
CTError
¶
Bases: FleetError
Raised when controlled terminology operations fail.
CTNotFoundError
¶
Bases: CTError, LookupError
Raised when the CDISC Library has no such resource (HTTP 404), unlike a 401 or a network error.
IOError
¶
Bases: FleetError
Raised when data loading or saving fails.
SpecError
¶
Bases: FleetError
Raised when a YAML specification is invalid.
SpecSchemaError
¶
Bases: SpecError, ValueError
Raised when a define.yaml fails its JSON schema.
A ValueError too, so code written for the earlier ValueError
keeps working; the CLI prints it as one clean message, with no traceback.
Source code in src/fleet/core/exceptions.py
ValidationError
¶
Bases: FleetError
Raised when CDISC validation encounters a fatal error.
ValidationSetupError
¶
Bases: FleetError, ValueError
Raised when a validation could not run: its run setup was refused.
Examples: the namespace and the dataset name point to different
standards, or the IG version is not supported. The verb raises it in
every on_fail mode, because no rule was reached.
Source code in src/fleet/core/exceptions.py
StudyRunError
¶
Bases: FleetError
Raised when a study run cannot plan or build a dataset.
Examples: no define file under the study's metadata directories, a dataset name the define files do not declare, an input that no seed, earlier step, declared path or data directory provides, or a seed that is also a step of the plan.
Source code in src/fleet/core/exceptions.py
ComparisonError
¶
Bases: FleetError, ValueError
Raised when a comparison cannot run: keys missing, duplicated or incompatible between the base and the candidate.
Differences between the two datasets never raise from
:func:fleet.compare; they are reported. The pipeline verb
.compare(..., on_fail="raise") is the one place that turns a
difference into this error, on request. Dual-inherits from
ValueError so except ValueError handlers keep working.
Source code in src/fleet/core/exceptions.py
TLGError
¶
Bases: FleetError
Raised when TLG namespace operations fail.
options: show_root_heading: true heading_level: 3 filters: ["!^_"]