Expressions
Typed wrappers for expr and schema (shape) operations, the core of Typol
AggExpr
dataclass
An expression created by an aggregation function (e.g. .sum()). This can't be used as a normal
expression, only as an aggregated value in an .agg(...) argument
Source code in typol/expr.py
over(*exprs, order_by=None, mapping_strategy='group_to_rows')
Restrict an aggregating expression to just a window (i.e. bucket) of values keyed on by
exprs. "group_to_rows" matches values up to the current rows, "join" matches them back to
the source rows, and "explode" does the same as join, but if there are multiple values from
the aggregating expression, it will duplicate the existing line into multiple per each
aggregated value:
# Find multiple ids attached to the same username
accounts.filter(Account.id.count().over(Account.username).gt(1))
Source code in typol/expr.py
BoundDimension
dataclass
Bases: Expr[_S_contra, _S_contra, _T]
This binds the shape to the dimension at the type level, which means this shape can then be enforced by all the operations using any dimension, and any expression created from this bound dimension can continue to refer to the shape it operates on in its type too by passing the type parameter along
Source code in typol/expr.py
map(transform)
Apply a Python transformation to the values in a column. This is defined on the dimension
rather than on Expr, to know the polars datatype of the output. To change the type, use
Expr.map_to
Source code in typol/expr.py
ChainedWhen
dataclass
Bases: Generic[_S_contra, _R_contra, _T]
A chain of when statements representing an if/elif chain. Construct by starting with a
tp.when(conds).then(if_true), and adding more .when(else_cond).then(else_true)s after
Source code in typol/expr.py
ColumnInitializer
dataclass
Bases: Generic[_S_contra, _T]
Used in dataframe constructors to initialize a dataframe column-wise
Source code in typol/expr.py
Dimension
dataclass
A shape Dimension declares a column in the dataclass. This should be a class-level field of
a Shape subtype, and will be a BoundDimension when accessed as MyShape.my_dimension
You must provide a type when declaring a dimension, and can optionally set a polars type implementation and an underlying name to use. By default, the name will be the name of the field
Source code in typol/expr.py
__get__(shape, shape_type=None)
This is the secret sauce: when a shape's dimensions are accessed by MyShape.my_dimension,
this binds the shape to the dimension at the type level, which means this shape can then
be enforced by all the operations using any dimension, and any expression created from this
bound dimension can continue to refer to the shape it operates on in its type too by passing
the type parameter along
Source code in typol/expr.py
DtExprNamespace
dataclass
Namespace for date and datetime functions, similar to pl.Expr.dt
Source code in typol/expr.py
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 | |
add_business_days(offset, roll='step')
Add offset business days to the current day. If the current day is not a business day, it
will be treated based on roll:
- `"step"`: Treat the first step from the current non-business day as if it is moving
from a business day. For zero, it heads to the business day it would move from to go
forwards (back 1)
- `"snap"`: In the direction of `offset`, move to a business day before adding. For
zero, it heads to the business day it would move from to go forwards (forward 1)
- `"raise"`: Throw an error if not starting on a business day
- `"forward"`: Snap to the next business day
- `"backward:` Snap to the previous business day
Source code in typol/expr.py
date()
day()
month()
month_end()
month_start()
offset_by(offset)
Add an amount of time to a date or datetime, see pl.offset_by for all allowed interval
strings, but examples include -1y or 6mo3m2s
Source code in typol/expr.py
total_days()
total_seconds()
The total number of seconds represented by the duration
weekday()
Day of week between 1 (Monday) and 7 (Sunday), you'll need to - 1 to be compatible with
import calendar
Element
Bases: Shape
Special shape containing pl.element() for mapping single element expressions, such as
list.eval
Source code in typol/expr.py
Explosion
dataclass
Bases: Generic[_S_contra, _R_contra, _T]
An expression that can "explode" a frame to a new row for each output value
Source code in typol/expr.py
Expr
Bases: ABC, Generic[_S_contra, _R_contra, _T]
Base class for all expressions, defining the common operations such as comparison and transformation
Source code in typol/expr.py
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 | |
agg()
cast(ty, *, strict=True)
Cast the values in the column whilst preserving the type, useful if two polars
representation have the same Python type (e.g. Float32 and Float64)
This is the _out variant, which is allowed to change type but must be mapped to a new
column if it is to be stored in a dataframe
Source code in typol/expr.py
cast_out(ty, *, strict=True)
Cast the values in the column to change the type, i.e. casting ints to strings.
This is the _out variant, which is allowed to change type but must be mapped to a new
column if it is to be stored in a dataframe
Source code in typol/expr.py
gather_every(n, offset=0)
implode()
Group all the elements into a single. This resizes the resultant series to a single element.
Note: Since this resizes the result, it is unsafe to simply map back to a column. Instead,
it's useful for creating arrays for intermediates used in ExoExprs. You might want
agg instead to create a aggregated list out of elements
Source code in typol/expr.py
is_between(start, end, closed='both')
Check if this expression is between the given lower and upper bounds
Source code in typol/expr.py
is_significant()
Is the numeric value a significant number, not nan, 0 or null
Source code in typol/expr.py
map_out(transform, ty)
Apply a Python transformation to the values in a column. This has to be mapped straight to a
dimension to know the polars datatype of the output. This limitation shouldn't be too
disruptive since the transform function in Python should be able to get it into its final
form, and since after being mapped to a column it can continue to be operated on
Source code in typol/expr.py
map_to(transform, to)
Apply a Python transformation to the values in a column. This has to be mapped straight to a
dimension to know the polars datatype of the output. This limitation shouldn't be too
disruptive since the transform function in Python should be able to get it into its final
form, and since after being mapped to a column it can continue to be operated on
Source code in typol/expr.py
null_insignificant()
null_when_eq(expr)
Replace any value equalling expr with null. E.g. .null_when_eq("NOT SET")
over(*exprs, order_by=None, mapping_strategy='group_to_rows')
over(
*exprs: ExoExpr[_S_contra, Any]
| ExoExpr[Q, Any]
| ExoExpr[Intersection[_S_contra, Q], Any],
order_by: Iterable[
ExoExpr[_S_contra, Any]
| ExoExpr[Q, Any]
| ExoExpr[Intersection[_S_contra, Q], Any]
]
| None = None,
mapping_strategy: Literal[
"group_to_rows"
] = "group_to_rows",
) -> MesoExpr[Intersection[_S_contra, Q], _T]
over(
*exprs: ExoExpr[_S_contra, Any]
| ExoExpr[Q, Any]
| ExoExpr[Intersection[_S_contra, Q], Any],
order_by: Iterable[
ExoExpr[_S_contra, Any]
| ExoExpr[Q, Any]
| ExoExpr[Intersection[_S_contra, Q], Any]
]
| None = None,
mapping_strategy: Literal["join"],
) -> MesoExpr[
Intersection[_S_contra, Q], builtins.list[_T]
]
Specify the expression is for the keyed group of the table. I.e.,
Specify the expression is for a window (i.e. bucket) of values keyed on by exprs.
"group_to_rows" matches values up to the current rows, "join" implodes the group and
matches this list back to each of the the source rows:
# Find accounts with a US-region account with the same username
accounts.filter(
Account.region.over(Account.username, mapping_strategy="join")
.list.contains("US")
)
Source code in typol/expr.py
repeat_by(by)
Create a list of the element repeated by times. Also useful for constructing singleton
lists with .repeat_by(0)
Source code in typol/expr.py
replace(mapping, *, default=None, or_null=False)
Translate the values in the column using the given lookup table. If the lookup fails,
this preserves the current value, use default or or_null to change this behaviour.
Source code in typol/expr.py
replace_out(mapping, ty, *, default=None, or_null=False)
Translate the values in the column using the given lookup table
This is the _out variant, which is allowed to change type but must be mapped to a new
column with .to if it is to be stored in a dataframe
Unlike replace, all values must be mapped or a default must be set, since the column type
is changing
Source code in typol/expr.py
replace_to(mapping, to, *, default=None, or_null=False)
Translate the values in the column using the given lookup table
This is the _to variant, which is allowed to change type but must be mapped to a new
column
Unlike replace, all values must be mapped or a default must be set, since the column type
can change
Source code in typol/expr.py
to_out(label)
The _out variant of to lets you rename a column, but it must be renamed again before it
can be stored in a shape. However, if you're going out to a file, this controls the output
column name, so is most useful with transform_write_csv
Source code in typol/expr.py
Initializer
dataclass
Bases: Expr[Any, _S_contra, _T]
Used in Entry.of to allow constructing rows where the dimension matches the assigned column
value
Source code in typol/expr.py
IntermediateExpr
dataclass
Bases: Expr[S, R, T]
An expression created from another expression, this just stores the polars expression generated from whatever operation has been applied to the last expression
Source code in typol/expr.py
JoinOn
dataclass
Bases: Generic[_S_contra, _R_contra, _T]
Represents a requirement for left and right to be equal for two rows to join
Source code in typol/expr.py
ListExprNamespace
dataclass
Namespace for list functions, similar to pl.Expr.list
Source code in typol/expr.py
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 | |
eval(expr)
Evaluate an expression against each element of the list, effectively map but for Polars.
Imagine we had the ages for various family members, and we wanted to know the age in 5 years time:
+---------+-----------+ | surname | ages | +---------+-----------+ | Baggins | [111, 33] | | Gamgee | [38] | +---------+-----------+
To transform these ages, we could do:
five_years_from_now = families.with_columns(
Family.ages.eval(Element.element() + 5).to(Family.ages)
)
Source code in typol/expr.py
explode()
Flatten a list expression into one entry per list element. This resizes the resultant series to the sum of the length of the lists.
Note: Since this resizes the result, it is unsafe to simply map back to a column. Instead, it's useful for flattening arrays before applying some aggregate expression
Source code in typol/expr.py
explode_to(to)
Explode the entire dataframe around for this list column, creating a new row for every list entry in a existing row
sort(descending=False)
PartialConditional
dataclass
Bases: Expr[_S_contra, _R_contra, _T]
The intermediate state where one outcome value has been provided but not the other, which
is assumed by default to be null. Use .otherwise to provide the other value, or .when
again to construct an if/elif chain
Source code in typol/expr.py
Projection
dataclass
Bases: Generic[_SProjection_contra]
Represent a projection of a potentially wider shape onto just this shape. This is useful for constructing a struct out of a wider shape
Source code in typol/expr.py
Shape
This is the core component of typed polars, that lets you define the static column names and types of a dataframe much like a dataclass.
defines a two-column dataframe with a str and an int column. Operations can be done on the
dataframe using the fields of the shape type, e.g.:
Source code in typol/expr.py
ShapeMeta
dataclass
A wrapper object that all library level definitions are on to avoid name conflicts with a shape's dimensions
This provides utilities for inspecting the shape and schema
Source code in typol/expr.py
datatypes
property
A mapping from dimension name to their polars data type
dimensions
property
Iterate through the dimensions defined in the shape
schema
property
A polars runtime schema to direct it how to configure (and enforce the types on) the dataframe
ShapeType
Bases: type
Metaclass defining shape-level operators
Source code in typol/expr.py
StrExprNamespace
dataclass
Namespace for string functions, similar to pl.Expr.str
Source code in typol/expr.py
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 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 | |
contains(substring, literal=False)
Whether each column value contains the regex (or if literal is set, the fixed-string)
Source code in typol/expr.py
contains_any(substrings, *, ascii_case_insensitive=False)
Whether each column value contains the regex (or if ascii_case_insensitive is set, then
the match can be either upper or lower case)
Source code in typol/expr.py
count_matches(substring, literal=False)
How many times each column value contains the regex pattern (or if literal is set, the
fixed-string)
Source code in typol/expr.py
ends_with(suffix)
Whether each column value ends with the given fixed string
escape_regex()
extract(pattern, group_index=1)
Extract the 1st or group_indexth regex capture group from the column
Source code in typol/expr.py
extract_all(pattern)
Extract all regex capture group as a list from the column
extract_groups(pattern)
Extract all regex capture group as a dict from the column
Source code in typol/expr.py
extract_many(patterns, *, ascii_case_insensitive=False, overlapping=False, leftmost=False)
Extract multiple fixed strings from the column
Source code in typol/expr.py
find(substring, *, literal=False, strict=True)
The index of the first match of the regex (or if literal is set, the fixed-string)
Source code in typol/expr.py
find_many(patterns, *, ascii_case_insensitive=False, overlapping=False, leftmost=False)
The index of the many matches of the fixed-strings
Source code in typol/expr.py
head(n)
join(sep)
Aggregate a group of strings by interspersing sep between them and concatenating
json_path_match(json_path)
Extract the value from the JSON string at the given path
Source code in typol/expr.py
len_bytes()
len_chars()
pad_end(length, fill_char=' ')
Ensure the strings are at least length long, adding fill_char to make up the difference
Source code in typol/expr.py
pad_start(length, fill_char=' ')
Ensure the strings are at least length long, adding fill_char to make up the difference
Source code in typol/expr.py
replace(pattern, value, literal=False, n=1)
Replace n matches for pattern (regex, or fixed-string if literal is True) with
value
Source code in typol/expr.py
replace_all(pattern, value, literal=False)
Replace all matches for pattern (regex, or fixed-string if literal is True) with
value
Source code in typol/expr.py
replace_many(patterns, replace_with, *, ascii_case_insensitive=False, leftmost=False)
Replace many matches for the fixed-string pattern with value
Source code in typol/expr.py
slice(offset, length=None)
Take characters starting from offset, up to offset + length, or the end of the string if
set to None
Source code in typol/expr.py
split(sep, *, inclusive=False, literal=False, strict=True)
Break a string into a list of strings, using sep as the separator
Source code in typol/expr.py
split_exact(sep, n, *, inclusive=False)
Break a string into a list of exactly n strings, using sep as the separator
Source code in typol/expr.py
splitn(sep, n)
Break a string into a list of n strings, using sep as the separator
Source code in typol/expr.py
starts_with(suffix)
Whether each column value starts with the given fixed string
strip_chars(characters=None)
Remove leading and trailing characters in the given string. By default removes whitespace
Source code in typol/expr.py
strip_chars_end(characters=None)
Remove trailing characters in the given string. By default removes whitespace
Source code in typol/expr.py
strip_chars_start(characters=None)
Remove leading characters in the given string. By default removes whitespace
Source code in typol/expr.py
strip_prefix(prefix=None)
Remove leading substring from the given string
Source code in typol/expr.py
strip_suffix(prefix=None)
Remove trailing substring from the given string
Source code in typol/expr.py
StructExprNamespace
dataclass
Namespace for struct functions
Source code in typol/expr.py
map_rows_to(transform, to)
Apply a Python transformation on Rows to the structs in a column
Source code in typol/expr.py
Suffixed
Bases: Shape
A suffixed shape allows modifying a shape with an additional tag after each column name.
This is critical in joins to avoid name conflicts, if two similarly named columns would
otherwise collide with each other. Use df.suffix() to conveniently add a suffix to an existing
dataframe.
To access dimensions of a suffixed shape, use the shape to transform the base shape, i.e.
my_shape = tp.DataFrame(...)
suffixed = my_shape.suffix()
col_a = suffixed[suffixed.s(my_shape.s.a)]
The above is a little clunky to use; suffixed shapes are only intended as brief intermediaries when name conflicts are possible
Source code in typol/expr.py
SuffixedShapeMeta
dataclass
Similar to ShapeMeta, but handle renaming the dimensions with the suffix
Source code in typol/expr.py
dimensions
property
Iterate through the dimensions defined in the shape
When
dataclass
Bases: Generic[_S_contra]
A condition that can be combined with a value using then and otherwise to construct a
conditional expression. Use tp.when rather than When(...) directly
Source code in typol/expr.py
all_horizontal(*conditions)
and all the given conditions, i.e. when all is true
Source code in typol/expr.py
any_horizontal(*conditions)
or all the given conditions, i.e. when any is true
Source code in typol/expr.py
concat_list(*exprs)
Combine various list expressions into a single list. Also useful for constructing lists,
with tp.concat_list([expr1, expr2])
Source code in typol/expr.py
date_range(start, end, interval='1d', closed='both')
Construct a series from start inclusive to end inclusive
Source code in typol/expr.py
date_ranges(start, end)
Construct a list for each element containing a date range from start to end inclusive
Source code in typol/expr.py
datetime_range(start, end, interval, closed='both')
Construct a series from start inclusive to end inclusive
Source code in typol/expr.py
duration(weeks=None, days=None, minutes=None, seconds=None, milliseconds=None, microseconds=None, nanoseconds=None)
Construct a duration, either from literals of column values
weeks = tp.duration(weeks=AccountingPeriod.week_count)
adjusted = Rate.date + tp.duration(days=Rate.adjustment_days, seconds=10)
Source code in typol/expr.py
int_range(value, end=None, step=1)
Construct a series from start inclusive to end exclusive. If end is unspecified, value is end,
otherwise value is start
Source code in typol/expr.py
length()
Count the number of rows in a shape or window. This is namespaced under Expr to avoid
conflicts with the len builtin
lit(value)
max_horizontal(*exprs)
Max the given exprs, i.e. take the largest. For pl.max, use Expr.max
Source code in typol/expr.py
min_horizontal(*exprs)
Min the given exprs, i.e. take the smallest. For pl.min, use Expr.min
Source code in typol/expr.py
null(ty)
projection(shape)
Construct a projection of a shape out of a potentially wider shaped dataframe
accounts = tp.DataFrame(Account, ...)
external_email = accounts.with_columns(
tp.projection(e := EmailDetails).struct()
.struct.map_rows_to(e.email + "@" + e.organization + ".com", e.email)
)
Source code in typol/expr.py
row_index()
Row number of the current line of the frame or window, starting at 0
Use this and a transform, i.e. .transform or .with_columns, if you're looking for
frame.with_row_index():
# Polars equivalent: frame.with_row_index("line_number")
frame.with_column(tp.row_index().to(Report.line_number))
Source code in typol/expr.py
struct(*exprs)
Construct a struct expression from the underlying expressions:
The above will create an expression that can be put into a column for
tp.dimension(tp.struct_of(Login)), or mapped with `.struct.map_rows_to(..., to)
Source code in typol/expr.py
suffix(shape, suffix=None)
Create a modified shape where each column name is suffixed:
suffixed = external_accounts.suffix(suff := suffix(ExternalAccount))
account_details = accounts.join(
suffixed,
Accounts.external_account_number.on(suff(ExternalAccounts.number))
).transform(
# Could not do this otherwise, as the Accounts.name and ExternalAccounts.name columns would
# conflict and Polars wouldn't be able to tell them apart (in regular Polars you'd also have
# to be explicit)
(Accounts.name + "-" + suff(ExternalAccounts.name)).to(AccountMatchup.name)
)
Parameters
suffix : str | None
The string literal to append to each column name. If None, this will be the name of the
shape itself