API index¶
Auto-generated index of the public surface of tsecon. Members are listed in the
order they appear in tsecon/__init__.py.
TimeSeriesEconPy: a time-series language for macroeconomics.
Ported from TimeSeriesEcon.jl_ (Bank of Canada).
.. _TimeSeriesEcon.jl: https://github.com/bankofcanada/TimeSeriesEcon.jl
MIRRORS_JULIA_SHA
module-attribute
¶
Commit SHA of bankofcanada/TimeSeriesEcon.jl mirrored by this release.
CompareDifference
dataclass
¶
One line of the recursive diff produced by :func:compare.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
tuple[str, ...]
|
Hierarchical tuple of names, e.g. |
message |
str
|
Short human-readable description: |
Source code in src/tsecon/_various.py
CompareResult
dataclass
¶
The structured return value of :func:compare.
Truthy iff the two inputs compared as equal — use
if compare(a, b): ... for the Julia-style one-line check.
str(result) reproduces the printed diff (one line per
:class:CompareDifference). .differences exposes the diff
programmatically.
Source code in src/tsecon/_various.py
BDaily
dataclass
¶
Bases: CalendarFrequency
Business-daily frequency (Monday-Friday, no weekends).
Source code in src/tsecon/frequencies.py
CalendarFrequency
dataclass
¶
Daily
dataclass
¶
Bases: CalendarFrequency
Daily frequency (every calendar day).
Source code in src/tsecon/frequencies.py
Frequency
dataclass
¶
Abstract supertype for all frequencies.
Concrete subclasses use cached singletons via __new__; do not
instantiate :class:Frequency directly.
Source code in src/tsecon/frequencies.py
HalfYearly
dataclass
¶
Bases: YPFrequency
Half-yearly frequency: 2 periods per year. Default end-month is June (6).
Source code in src/tsecon/frequencies.py
Monthly
dataclass
¶
Bases: YPFrequency
Monthly frequency: 12 periods per year.
Source code in src/tsecon/frequencies.py
Quarterly
dataclass
¶
Bases: YPFrequency
Quarterly frequency: 4 periods per year. Default end-month is March (3).
Source code in src/tsecon/frequencies.py
Unit
dataclass
¶
Bases: Frequency
Non-dimensional frequency (no calendar association).
Source code in src/tsecon/frequencies.py
Weekly
dataclass
¶
Bases: CalendarFrequency
Weekly frequency. end_day is the ISO weekday the week ends on (Mon=1..Sun=7).
Default is end_day=7 (Sunday).
Source code in src/tsecon/frequencies.py
Yearly
dataclass
¶
Bases: YPFrequency
Yearly frequency: 1 period per year. Default end-month is December (12).
Source code in src/tsecon/frequencies.py
YPFrequency
dataclass
¶
Bases: CalendarFrequency
Abstract supertype for fixed-periods-per-year calendar frequencies.
Subclasses provide a class-level :attr:periods_per_year integer N. An
MIT{F} value for F <: YPFrequency decomposes into a (year, period)
pair via int(mit) = N * year + (period - 1).
Source code in src/tsecon/frequencies.py
MIT
dataclass
¶
A frequency-tagged moment in time.
Construct via :meth:from_yp for year/period frequencies, or via the
convenience constructors :func:qq, :func:mm, :func:yy, :func:daily,
:func:bdaily, :func:weekly. Direct MIT(frequency, value)
construction takes a raw integer offset.
Source code in src/tsecon/mit.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 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 | |
from_yp
classmethod
¶
Construct an MIT from year+period (only for YP frequencies).
Source code in src/tsecon/mit.py
to ¶
Return the MITRange from self through stop (inclusive).
Mirrors Julia's start:stop syntax for MITs. Python's slice/colon
cannot be overloaded outside of indexing, so this method is the
idiomatic spelling. The free function :func:tsecon.mitrange.mitrange
also works.
Source code in src/tsecon/mit.py
Duration
dataclass
¶
A frequency-tagged distance between two MITs.
Source code in src/tsecon/mit.py
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 | |
MITRange
dataclass
¶
An inclusive range of MITs of a single frequency.
Construct with MITRange(start, stop) for unit steps, or
MITRange(start, stop, step) for a step range. step may be a
nonzero int (interpreted in the range's frequency) or a
:class:Duration of the same frequency. Negative step walks
backward (MITRange(10U, 1U, -1) mirrors Julia's 10U:-1:1U);
ranges whose endpoints have the opposite sense to step are empty.
Source code in src/tsecon/mitrange.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
is_empty ¶
first ¶
last ¶
Return the last MIT in the range. Raises if empty.
For a forward range (step > 0) this is the largest MIT not past
stop; for a reversed range (step < 0) it is the smallest
MIT not past stop. In both cases, last() == start + (len-1) * step.
Source code in src/tsecon/mitrange.py
MVTSeries ¶
A 2-D NumPy array paired with a frequency-tagged firstdate and named columns.
See the module docstring for the storage model and the wrap-vs-copy contract on the constructor.
Source code in src/tsecon/mvtseries.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 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 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 | |
values
property
¶
The underlying 2-D NumPy array. Mutating it mutates the MVTSeries.
lastdate
property
¶
The MIT of the last stored row. Undefined when the MVTSeries is empty.
range
property
¶
The MITRange covering firstdate..lastdate.
For an empty MVTSeries (no rows) returns an empty MITRange.
columns
property
¶
The column-name → TSeries-view mapping (live; do not mutate keys).
empty
classmethod
¶
Construct an uninitialized MVTSeries (typenan-filled).
zeros
classmethod
¶
Construct an MVTSeries of zeros.
ones
classmethod
¶
Construct an MVTSeries of ones.
fill
classmethod
¶
fill(
rng: MITRange,
names: _NamesLike,
value: float | int | bool,
*,
dtype: DTypeLike | None = None,
) -> MVTSeries
Construct an MVTSeries filled with value.
Source code in src/tsecon/mvtseries.py
keys ¶
is_empty ¶
copy ¶
Return an independent copy with its own matrix buffer.
deep is accepted for API uniformity with
:meth:~tsecon.tseries.TSeries.copy and
:meth:~tsecon.workspace.Workspace.copy; for MVTSeries it is a
semantic no-op because the only mutable referents below the
wrapper are the matrix buffer (always copied) and the per-column
TSeries views (which are rebuilt to point at the fresh buffer).
Source code in src/tsecon/mvtseries.py
similar ¶
similar(
*,
dtype: DTypeLike | None = None,
rng: MITRange | None = None,
names: _NamesLike | None = None,
) -> MVTSeries
Return an uninitialized MVTSeries with matching shape (or overrides).
Source code in src/tsecon/mvtseries.py
equals ¶
Return True iff other is an MVTSeries with same freq/range/cols/values.
Source code in src/tsecon/mvtseries.py
allclose ¶
Return True iff other is a same-shape MVTSeries with close values.
Source code in src/tsecon/mvtseries.py
BackendNotAvailableError ¶
TSeries ¶
A 1-D NumPy array paired with a frequency-tagged firstdate.
Construct with TSeries(firstdate, values) where firstdate is an
:class:~tsecon.mit.MIT or :class:~tsecon.mitrange.MITRange. When the
first argument is an MITRange, the second may be omitted (uninitialized,
NaN-filled storage), a scalar (fill), or a length-matching array. See
the class-level constructors :meth:empty, :meth:zeros, :meth:ones,
:meth:fill for keyword-named convenience constructors.
Source code in src/tsecon/tseries.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 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 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 | |
range
property
¶
The MITRange covering firstdate..lastdate.
Empty TSeries return an empty MITRange (start > stop).
empty
classmethod
¶
Construct an uninitialized TSeries over rng filled with the dtype's NaN.
fill
classmethod
¶
Construct a TSeries over rng filled with value.
zeros
classmethod
¶
ones
classmethod
¶
trues
classmethod
¶
falses
classmethod
¶
is_empty ¶
any ¶
all ¶
copy ¶
Return an independent copy with its own storage.
The deep kwarg is accepted for API uniformity with container
types (:class:~tsecon.workspace.Workspace, MVTSeries) where a
shallow copy would share value references. TSeries has no nested
containers — the underlying ndarray is always copied — so
deep=True is a semantic no-op here.
Source code in src/tsecon/tseries.py
similar ¶
Return an uninitialized TSeries with matching shape (or the given range).
Source code in src/tsecon/tseries.py
resize ¶
Extend or shrink storage so the new range equals rng.
New entries are filled with the dtype's NaN sentinel. The TSeries is modified in place; the same object is returned for chaining.
Source code in src/tsecon/tseries.py
equals ¶
Return True iff other is a TSeries with identical freq, range, and values.
Source code in src/tsecon/tseries.py
allclose ¶
Return True iff other is a same-shape TSeries with close values.
Source code in src/tsecon/tseries.py
Workspace ¶
Insertion-ordered, name-indexed collection of arbitrary values.
Construct with one of:
Workspace()— empty.Workspace(a=1, b=2)— from keyword arguments.Workspace({"a": 1, "b": 2})— from a mapping.Workspace([("a", 1), ("b", 2)])— from an iterable of pairs.
Access by attribute (w.a) or by key (w["a"]); subset by tuple or
list of keys (w["a", "b"] or w[["a", "b"]]) to get a new Workspace.
Keys must be strings. (Julia uses Symbol; we standardize on str
since Python has no analogue and attribute access naturally produces
strings.)
Source code in src/tsecon/workspace.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 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 | |
from_dict
classmethod
¶
Build a Workspace from a mapping.
With recursive=True, any nested Mapping value is itself
converted to a Workspace, recursively. Mirrors the Julia
Workspace(d; recursive=true) constructor.
Source code in src/tsecon/workspace.py
keys ¶
values ¶
items ¶
get ¶
is_empty ¶
as_namespace ¶
Yield a snapshot of members as attributes on a SimpleNamespace.
Use as a context manager to scope unprefixed access to the Workspace's members::
with w.as_namespace() as ns:
y = ns.a + ns.b
The snapshot is taken at __enter__: subsequent mutations to
either side are independent. Members whose keys are not valid
Python identifiers are silently omitted (they cannot be reached
via attribute syntax anyway — use w["..."] for those). Values
are held by reference, so mutating a contained TSeries / MVTSeries
through the namespace also mutates the same object in self.
The Pythonic alternative to Julia's @weval(W, EXPR) macro.
For most call sites direct attribute access w.a + w.b is
shorter and clearer; reach for as_namespace only when several
unprefixed reads in a row earn their keep over the explicit prefix.
Source code in src/tsecon/workspace.py
merge ¶
Return a new Workspace with other's entries overlaid onto a copy of self.
Mirrors Julia's merge(a, b). Keys in other win over keys in
self.
Source code in src/tsecon/workspace.py
merge_inplace ¶
Update self in place with entries from other (other wins).
Returns self for chaining. Mirrors Julia's merge!(a, b).
Source code in src/tsecon/workspace.py
empty_inplace ¶
copy ¶
Return a copy of the Workspace.
With deep=False (the default) the storage dict is fresh but
values are shared by reference — Python-dict semantics. With
deep=True, every value is recursively :func:copy.deepcopy-ed,
equivalent to copy.deepcopy(self). The kwarg matches the
:meth:TSeries.copy signature for API uniformity.
Source code in src/tsecon/workspace.py
filter ¶
Return a new Workspace containing only the (k, v) pairs that pass predicate.
Predicate is called as predicate(key, value). Mirrors Julia's
filter(tuple -> ..., w) (where tuple is a (key, value)
pair).
Source code in src/tsecon/workspace.py
filter_inplace ¶
Drop entries that fail predicate; mutates and returns self.
Source code in src/tsecon/workspace.py
map ¶
Apply f to each member's value; return a new Workspace.
Keys are preserved. Mirrors Julia's map(f, w).
strip_inplace ¶
Trim leading/trailing NaN values from every TSeries member.
With recursive=True (the default) also strips TSeries inside
nested Workspaces. Mirrors Julia's strip!(w; recursive).
Delegates the per-TSeries trim to
:func:tsecon.fconvert.strip_tseries_inplace. Bool-dtype TSeries are
left alone (their typenan is False, which would erase the array).
Source code in src/tsecon/workspace.py
frequency_of ¶
Return the common frequency of all frequency-bearing members, or None.
Recurses through nested Workspaces. If members carry distinct
frequencies, returns None (or raises ValueError if
check=True). With check=True and no frequency-bearing
members, also raises.
Source code in src/tsecon/workspace.py
rangeof ¶
Return the combined range of all rangeable members.
Frequency-bearing members must share a single frequency, else
TypeError is raised. Members without a range (scalars, strings,
etc.) are skipped. If no member has a range, raises ValueError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
|
'intersect'
|
Source code in src/tsecon/workspace.py
rangeof_span ¶
Return the smallest range covering all rangeable members.
Frequency must be consistent across rangeable members. Mirrors
Julia's rangeof_span(values(w)...) idiom.
Source code in src/tsecon/workspace.py
bdvalues ¶
Return values of t masked by holidays_map.
holidays_map must be a BDaily Boolean :class:~tsecon.tseries.TSeries
that spans t.range. Entries where the map is False are dropped;
the result is the underlying ndarray (1-D for TSeries, 2-D for MVTSeries)
indexed by the Boolean mask.
Source code in src/tsecon/_bdaily.py
cleanedvalues ¶
cleanedvalues(
t: TSeries | MVTSeries,
*,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> np.ndarray
Return a filtered view of the underlying values of a BDaily series.
Behaviour mirrors Julia's cleanedvalues overloads:
holidays_mapis given → use that map; entries where the map isFalseare dropped.holidays_map is Noneandskip_all_nans=True→ drop NaN entries. For an :class:~tsecon.mvtseries.MVTSeries, only rows where all columns are NaN are dropped; rows where some columns are NaN and some are not emit a :class:UserWarningand are also dropped.holidays_map is Noneandskip_holidays=True→ fetch the global map fromgetoption("bdaily_holidays_map"); raise if missing.- No kwargs → return the underlying values unchanged.
The 1-D return is t.values for a :class:~tsecon.tseries.TSeries; the
2-D return is mvts.values (an (rows, cols) view) for an
:class:~tsecon.mvtseries.MVTSeries.
Source code in src/tsecon/_bdaily.py
apct ¶
Annualised percent rate of change.
Requires a :class:~tsecon.frequencies.YPFrequency (Yearly / HalfYearly /
Quarterly / Monthly). The annualisation exponent is ppy(t.frequency).
Source code in src/tsecon/_math.py
diff ¶
diff(
t: TSeries | MVTSeries,
k: int = -1,
*,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> TSeries | MVTSeries
First (or k-th) difference of t.
Defined as t - shift(t, k). With the default k=-1 (subtract the
lag), this matches the standard first-difference operator.
For an :class:~tsecon.mvtseries.MVTSeries the operation is performed
column-wise; the result is a new MVTSeries one row shorter (for
|k|=1). BDaily kwargs are forwarded to the inner lag call so
NaN/holiday infill is applied to the lag side of the subtraction
(mirrors Base.diff(::TSeries{BDaily}) in tseries.jl).
Source code in src/tsecon/_math.py
lag ¶
lag(
t: TSeries | MVTSeries,
k: int = 1,
*,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> TSeries | MVTSeries
Return the k-th lag. Same as shift(t, -k).
Source code in src/tsecon/_math.py
lag_inplace ¶
lag_inplace(
t: TSeries | MVTSeries,
k: int = 1,
*,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> TSeries | MVTSeries
In-place version of :func:lag.
Source code in src/tsecon/_math.py
lead ¶
lead(
t: TSeries | MVTSeries,
k: int = 1,
*,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> TSeries | MVTSeries
Return the k-th lead. Same as shift(t, k).
Source code in src/tsecon/_math.py
lead_inplace ¶
lead_inplace(
t: TSeries | MVTSeries,
k: int = 1,
*,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> TSeries | MVTSeries
In-place version of :func:lead.
Source code in src/tsecon/_math.py
moving ¶
Compute the moving average of t over a window of n periods.
If n > 0 the window is backward-looking (-n+1 .. 0) (the result at
period p is the mean of t[p-n+1 .. p]). If n < 0 the window is
forward-looking (0 .. -n-1) (the result at p is the mean of
t[p .. p+|n|-1]).
The returned series has length len(t) - |n| + 1. For n > 0 its
firstdate is t.firstdate + n - 1; for n < 0 it is
t.firstdate.
Identical to :func:moving_average; the bare name matches the Julia
convention. Accepts a :class:~tsecon.tseries.TSeries or
:class:~tsecon.mvtseries.MVTSeries.
Source code in src/tsecon/_math.py
moving_average ¶
Compute the moving average of t over a window of n periods. See :func:moving.
Source code in src/tsecon/_math.py
moving_sum ¶
Compute the rolling sum of t over a window of n periods.
Identical to :func:moving_average but without dividing by |n|.
Source code in src/tsecon/_math.py
pct ¶
pct(
t: TSeries | MVTSeries,
shift_value: int = -1,
*,
islog: bool = False,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> TSeries | MVTSeries
Observation-to-observation percent rate of change.
When islog is True, t is interpreted as a log-series — values
are exponentiated before differencing.
For BDaily series, accepts skip_all_nans / skip_holidays /
holidays_map kwargs. The kwargs are forwarded to the inner
:func:shift call (the value that ends up in the denominator), so NaN
/ holiday infill on the shift result propagates into the resulting
percent series.
Source code in src/tsecon/_math.py
shift ¶
shift(
t: TSeries | MVTSeries,
k: int,
*,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> TSeries | MVTSeries
Return a copy of t with its dates shifted by k periods.
By convention, positive k produces the lead (the value at t+k is
read at t); negative k produces the lag. The returned series has
the same values but firstdate moved by -k periods.
Accepts a :class:~tsecon.tseries.TSeries or
:class:~tsecon.mvtseries.MVTSeries.
BDaily kwargs (skip_all_nans / skip_holidays / holidays_map)
are accepted only when t.frequency is :class:BDaily; on the shifted
result they run :func:tsecon._bdaily.replace_nans_if_warranted to
infill NaN entries. For an MVTSeries{BDaily} the infill is applied
per-column (this extends Julia's TSeries-only overload — Julia's
MVTSeries shift has no kwarg path, so a Python user passing kwargs would
otherwise just lose them).
Source code in src/tsecon/_math.py
shift_inplace ¶
shift_inplace(
t: TSeries | MVTSeries,
k: int,
*,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> TSeries | MVTSeries
In-place version of :func:shift. Mutates the firstdate(s) and returns the same object.
Source code in src/tsecon/_math.py
undiff ¶
Inverse of :func:diff (cumulative sum, anchored at a known value).
dvar is the differenced series. anchor says what the integrated
series equals at some anchor date; the result is the cumulative sum of
dvar shifted so that result[date] == value. Forms accepted:
anchor=v(a number, default0) — anchor date defaults tofirstdate(dvar) - 1(the period just before the differencing window). If that date is outsidedvar.range,dvaris extended with zeros so that the anchor falls inside.anchor=(date, value)— both date and value given explicitly.anchor=other_tseries— anchor date defaults tofirstdate(dvar)-1; the value is read fromother_tseriesat that date.anchor=(date, other_tseries)— value is read fromother_tseries[date].
Forward vs. backward integration
The math is direction-agnostic: undiff computes a cumulative sum and
chooses the constant of integration so result[anchor_date] == anchor_value.
The anchor's position determines the user-visible direction:
- Forward — anchor at or before
firstdate(dvar) - 1(the defaultanchor=vform). Values past the anchor are accumulated forward. - Backward (backcasting) — anchor at
lastdate(dvar)or later, e.g.undiff(dvar, (dvar.lastdate, terminal_value)). Values before the anchor are recovered by walking the same cumulative-sum curve backward; result spansdvar.range.
An anchor strictly after lastdate(dvar) extends dvar with zeros
so the anchor falls inside the new range — the tail (positions strictly
between lastdate(dvar) and the anchor) is flat at the anchor value.
Note on a mid-range anchor: when date falls inside dvar.range, the
cumulative sum is still computed over the full range; the result is then
shifted by a constant so result[date] == value — every other period
moves by the same constant. See undiff_inplace for the alternative
semantics where dvar values at and before fromdate are ignored.
On an :class:~tsecon.mvtseries.MVTSeries, anchor may additionally
be a vector / matrix (one entry per column) or another MVTSeries; the
cumulative sum is performed column-wise.
Dispatch
The TSeries path's hot loop (cumsum over the integrated chunk +
constant-shift correction) routes through the
:func:tsecon._math_kernels.cumsum_anchored_numpy /
:func:tsecon._math_kernels_cy.cumsum_anchored_cython kernel pair
when the integrated buffer is float64 + C-contiguous; use
:func:undiff_is_cython to check which path is active. Integer
dvar + integer anchor combinations (which would broaden the
result dtype away from float64) stay on the pure-NumPy path
so the integer return type is preserved. The MVTSeries path stays
pure NumPy in M1.6 — np.cumsum(..., axis=0) already runs the
column-wise reduction in C, and the outer benchmark ratio sits at
14× rather than the 25-80× band the kernel addresses.
Source code in src/tsecon/_math.py
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 | |
undiff_inplace ¶
Anchor-based undiff that writes into var (mirrors Julia undiff!).
Reads the anchor value from var[fromdate] and writes the integrated
series into var at fromdate+1 .. lastdate(dvar). Values of var
at and before fromdate are left untouched, and values of dvar at
and before fromdate are ignored (treated as zero).
If var does not yet extend to lastdate(dvar), it is resized
(extending the end). fromdate defaults to firstdate(dvar) - 1 and
must satisfy fromdate >= firstdate(var).
.. note::
The semantics here differ from :func:undiff when fromdate falls
in the middle of rangeof(dvar). There, :func:undiff shifts the
whole cumulative result so result[fromdate] == value;
:func:undiff_inplace zeros out the earlier dvar entries instead,
so the integrated tail starts cleanly from the existing anchor.
Dispatch
Shares the cumsum + anchor-shift kernel with :func:undiff — the
inplace variant calls into the same
:func:tsecon._math_kernels.cumsum_anchored_numpy /
:func:tsecon._math_kernels_cy.cumsum_anchored_cython pair with
anchor_relative_idx = -1 (the anchor sits one position before
the integrated chunk, so the correction collapses to a single
fused add per element). Use :func:undiff_is_cython to check
which path is active. The kernel only engages when var.values
is float64 + C-contiguous; other dtypes fall back to the
pre-existing np.cumsum path.
Source code in src/tsecon/_math.py
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 | |
undiff_is_cython ¶
Return True iff the Cython-compiled cumsum-anchored kernel was importable.
Useful for tests, benchmarks, and diagnostic prints — the public
:func:undiff and :func:undiff_inplace are implementation-
agnostic. When this returns False the same calls go through
the pure-NumPy kernel in _math_kernels.py; behaviour is
identical, only speed differs.
The fast path also requires the integrated buffer to be float64
+ C-contiguous (the canonical kernel-eligibility contract); when
either condition fails (e.g. integer dvar with integer
anchor), the call routes through np.cumsum even when the
extension is importable.
Source code in src/tsecon/_math.py
ytypct ¶
Year-to-year percent change.
Requires a :class:~tsecon.frequencies.YPFrequency. Implemented as
100 * (t / shift(t, -ppy(t.frequency)) - 1).
Source code in src/tsecon/_math.py
clear_holidays_map ¶
get_holidays_map ¶
get_holidays_options ¶
List supported country codes (or subdivisions of a given country).
Mirrors Julia's get_holidays_options(country=nothing). Both no-arg
and country-arg forms return a sorted tuple. Subdivisions are reported
using the country's native code (ISO 3166-2 short form), exactly as
the holidays package exposes them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
country
|
str | None
|
Optional country code accepted by
:func: |
None
|
Returns:
| Type | Description |
|---|---|
tuple of str
|
Sorted country codes (no arg) or sorted subdivision codes (one arg). A country with no subdivisions returns an empty tuple. |
Raises:
| Type | Description |
|---|---|
ImportError
|
The |
ValueError
|
|
Source code in src/tsecon/_options.py
getoption ¶
Return the current value of a recognised option.
Raises :class:KeyError for unknown names.
Source code in src/tsecon/_options.py
option_scope ¶
Context manager that temporarily overrides one or more options.
On exit, every overridden option is restored to its prior value.
Convenient for tests; the wrapper goes through :func:setoption so the
same validation applies.
Source code in src/tsecon/_options.py
set_holidays_map ¶
Install a BDaily Boolean holidays map under bdaily_holidays_map.
Two call forms:
set_holidays_map(t)— install a pre-built BDaily Boolean :class:~tsecon.tseries.TSeries(True= business day,False= holiday).set_holidays_map("CA", "ON")— fetch the calendar for the given country / subdivision from theholidaysPyPI package, build a BDaily Boolean TSeries spanningbdaily("1970-01-01")tobdaily("2049-12-31")(matches the Julia upstream's default range), and install it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
Any
|
Either a pre-built BDaily Boolean :class: |
required |
subdivision
|
str | None
|
Optional subdivision code (ISO 3166-2 short form, e.g. |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
|
ValueError
|
|
TypeError
|
|
Notes
The country / subdivision codes follow the python-holidays
package's conventions (ISO 3166), which differ in minor cases from
the Julia upstream's CSV-derived names (e.g. the Julia CSVs spell
a few subdivisions with spaces that the package replaces with
underscores or drops). The package is the single source of truth;
discover the supported codes with :func:get_holidays_options.
Examples:
>>> set_holidays_map("DK") # Denmark, federal holidays
>>> set_holidays_map("CA", "ON") # Ontario, Canada
>>> from tsecon import bdaily, TSeries, MITRange
>>> cal = TSeries.trues(MITRange(bdaily("2022-01-03"), bdaily("2022-12-30")))
>>> set_holidays_map(cal) # pre-built TSeries
Source code in src/tsecon/_options.py
setoption ¶
Set the value of a recognised option, validating its type.
bdaily_creation_bias— must be one of"strict","previous","next","nearest".bdaily_holidays_map— must beNoneor a Boolean BDaily :class:~tsecon.tseries.TSeries.x13path— must be a string.
Source code in src/tsecon/_options.py
cor ¶
cor(
x: TSeries | MVTSeries,
y: TSeries | None = None,
*,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> Any
Pearson correlation.
Mirrors Julia's Statistics.cor overloads in tsmath.jl
(lines 249-272 and 297). Two call shapes:
cor(t)— for a :class:~tsecon.tseries.TSeriesthis returns1.0(the trivial self-correlation). For an :class:~tsecon.mvtseries.MVTSeriesit returns the column- correlation matrix (variables on rows = columns of the input).cor(x, y)— two TSeries of the same frequency, firstdate and length; returns the scalar Pearson correlation between them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
TSeries or MVTSeries
|
First operand (or sole operand in the |
required |
y
|
TSeries
|
Second operand. When given, both |
None
|
skip_all_nans
|
bool
|
BDaily only. If |
False
|
skip_holidays
|
bool
|
BDaily only. If |
False
|
holidays_map
|
TSeries
|
BDaily only. Boolean TSeries flagging which business days to keep. |
None
|
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Scalar in the single-TSeries or two-TSeries forms; an |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
Notes
Correlation of a constant series is mathematically undefined (zero
variance in the denominator). cor(x, y) returns nan and emits
a RuntimeWarning when either input is bit-exactly constant, matching
NumPy's np.corrcoef semantics on FP-exact constant input. The
explicit guard is uniform across the NumPy and Cython kernels, so the
return is nan for both np.full(N, 1.0) (where np.corrcoef
itself would warn) and np.full(N, 1e-60) (where pairwise summation
in np.corrcoef would otherwise silently return 1.0).
Examples:
>>> import numpy as np
>>> import tsecon as tse
>>> x = tse.TSeries(tse.qq(2020, 1), np.array([1.0, 2.0, 3.0, 4.0]))
>>> y = tse.TSeries(tse.qq(2020, 1), np.array([2.0, 4.0, 6.0, 8.0]))
>>> float(tse.cor(x, y))
1.0
Source code in src/tsecon/_stats.py
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 | |
cov ¶
cov(
x: TSeries | MVTSeries,
y: TSeries | None = None,
*,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> Any
Sample covariance (ddof=1 to match Julia's Statistics.cov).
Same call shapes as :func:cor:
cov(t)for a TSeries collapses to :func:var.cov(mvts)returns the column-covariance matrix.cov(x, y)returns the scalar covariance between two TSeries of the same frequency, firstdate, and length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
TSeries or MVTSeries
|
First operand (or sole operand in the |
required |
y
|
TSeries
|
Second operand. When given, both |
None
|
skip_all_nans
|
bool
|
BDaily only. If |
False
|
skip_holidays
|
bool
|
BDaily only. If |
False
|
holidays_map
|
TSeries
|
BDaily only. Boolean TSeries flagging which business days to keep. |
None
|
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Scalar in the TSeries forms; an |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
Examples:
>>> import numpy as np
>>> import tsecon as tse
>>> x = tse.TSeries(tse.qq(2020, 1), np.array([1.0, 2.0, 3.0]))
>>> y = tse.TSeries(tse.qq(2020, 1), np.array([2.0, 4.0, 6.0]))
>>> float(tse.cov(x, y))
2.0
Source code in src/tsecon/_stats.py
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 | |
mean ¶
mean(
t: TSeries | MVTSeries,
*,
axis: int | None = None,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> Any
Arithmetic mean.
For a :class:~tsecon.tseries.TSeries returns a scalar; for an
:class:~tsecon.mvtseries.MVTSeries the default (axis=None) returns
the overall mean (matching Julia's mean(::MVTSeries) which iterates
the matrix flat). axis=0 reduces along rows to a single-row
MVTSeries (per-column means); axis=1 reduces along columns to a 1-D
TSeries (per-row means).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
TSeries or MVTSeries
|
Input series. Any non-Unit frequency. |
required |
axis
|
int or None
|
Reduction axis (NumPy convention).
|
None
|
skip_all_nans
|
bool
|
BDaily only. If |
False
|
skip_holidays
|
bool
|
BDaily only. If |
False
|
holidays_map
|
TSeries
|
BDaily only. Boolean TSeries flagging the business days to
include ( |
None
|
Returns:
| Type | Description |
|---|---|
float, MVTSeries, or TSeries
|
Scalar for |
Examples:
>>> import numpy as np
>>> import tsecon as tse
>>> t = tse.TSeries(tse.qq(2020, 1), np.array([1.0, 2.0, 3.0, 4.0]))
>>> tse.mean(t)
2.5
Per-column reduction on an MVTSeries:
>>> m = tse.MVTSeries(tse.qq(2020, 1), ("a", "b"),
... np.array([[1.0, 10.0], [2.0, 20.0], [3.0, 30.0]]))
>>> tse.mean(m, axis=0)["a"][tse.qq(2020, 1)]
2.0
Per-row reduction on an MVTSeries:
Source code in src/tsecon/_stats.py
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 | |
median ¶
median(
t: TSeries | MVTSeries,
*,
axis: int | None = None,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> Any
Median value.
Mirrors Julia's Statistics.median. For an even-length input the
midpoint of the two middle values is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
TSeries or MVTSeries
|
Input series. Any non-Unit frequency. |
required |
axis
|
int or None
|
Reduction axis (NumPy convention; see :func: |
None
|
skip_all_nans
|
bool
|
BDaily only. If |
False
|
skip_holidays
|
bool
|
BDaily only. If |
False
|
holidays_map
|
TSeries
|
BDaily only. Boolean TSeries flagging which business days to keep. |
None
|
Returns:
| Type | Description |
|---|---|
float, MVTSeries, or TSeries
|
The median of the resolved values. Scalar for |
Examples:
>>> import numpy as np
>>> import tsecon as tse
>>> t = tse.TSeries(tse.qq(2020, 1), np.array([1.0, 2.0, 3.0, 4.0]))
>>> float(tse.median(t))
2.5
Source code in src/tsecon/_stats.py
quantile ¶
quantile(
t: TSeries | MVTSeries,
p: float | ndarray,
*,
axis: int | None = None,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> Any
p-th quantile of the series' values.
Mirrors Julia's Statistics.quantile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
TSeries or MVTSeries
|
Input series. Any non-Unit frequency. |
required |
p
|
float or array-like of float
|
Probability (or probabilities) in |
required |
axis
|
int or None
|
Reduction axis (NumPy convention; see :func: |
None
|
skip_all_nans
|
bool
|
BDaily only. If |
False
|
skip_holidays
|
bool
|
BDaily only. If |
False
|
holidays_map
|
TSeries
|
BDaily only. Boolean TSeries flagging which business days to keep. |
None
|
Returns:
| Type | Description |
|---|---|
float, ndarray, MVTSeries, or TSeries
|
Scalar when |
Examples:
>>> import numpy as np
>>> import tsecon as tse
>>> t = tse.TSeries(tse.qq(2020, 1), np.array([1.0, 2.0, 3.0, 4.0]))
>>> float(tse.quantile(t, 0.5))
2.5
Source code in src/tsecon/_stats.py
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 | |
stats_is_cython ¶
Return True iff the Cython-compiled stats kernels were importable.
Useful for tests, benchmarks, and diagnostic prints — the public
:func:mean / :func:var / :func:std / :func:cor are
implementation-agnostic. When this returns False the same calls
go through the pure-NumPy kernels in _stats_kernels.py;
behaviour is identical, only speed differs.
Source code in src/tsecon/_stats.py
std ¶
std(
t: TSeries | MVTSeries,
*,
axis: int | None = None,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> Any
Sample standard deviation.
Uses ddof=1 to match Julia's Statistics.std (corrected=true
by default). Pass np.std(t.values, ddof=0) directly if you need the
population deviation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
TSeries or MVTSeries
|
Input series. Any non-Unit frequency. |
required |
axis
|
int or None
|
Reduction axis (NumPy convention; see :func: |
None
|
skip_all_nans
|
bool
|
BDaily only. If |
False
|
skip_holidays
|
bool
|
BDaily only. If |
False
|
holidays_map
|
TSeries
|
BDaily only. Boolean TSeries flagging which business days to keep. |
None
|
Returns:
| Type | Description |
|---|---|
float, MVTSeries, or TSeries
|
Sample standard deviation with |
Examples:
>>> import numpy as np
>>> import tsecon as tse
>>> t = tse.TSeries(tse.qq(2020, 1), np.array([1.0, 2.0, 3.0]))
>>> tse.std(t)
1.0
Source code in src/tsecon/_stats.py
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 | |
stdm ¶
stdm(
t: TSeries,
m: float,
*,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> Any
Sample standard deviation with the mean m supplied externally.
Mirrors Julia's Statistics.stdm. Use this when you already have
the mean (perhaps a known population mean, or one shared across
several reductions) and want to avoid a redundant pass over t.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
TSeries
|
Input series. Any non-Unit frequency. |
required |
m
|
float
|
The mean to centre around. Not validated against |
required |
skip_all_nans
|
bool
|
BDaily only. If |
False
|
skip_holidays
|
bool
|
BDaily only. If |
False
|
holidays_map
|
TSeries
|
BDaily only. Boolean TSeries flagging which business days to keep. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
|
Examples:
>>> import numpy as np
>>> import tsecon as tse
>>> t = tse.TSeries(tse.qq(2020, 1), np.array([1.0, 2.0, 3.0]))
>>> tse.stdm(t, 2.0)
1.0
Source code in src/tsecon/_stats.py
var ¶
var(
t: TSeries | MVTSeries,
*,
axis: int | None = None,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> Any
Sample variance (ddof=1 to match Julia's Statistics.var).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
TSeries or MVTSeries
|
Input series. Any non-Unit frequency. |
required |
axis
|
int or None
|
Reduction axis (NumPy convention; see :func: |
None
|
skip_all_nans
|
bool
|
BDaily only. If |
False
|
skip_holidays
|
bool
|
BDaily only. If |
False
|
holidays_map
|
TSeries
|
BDaily only. Boolean TSeries flagging which business days to keep. |
None
|
Returns:
| Type | Description |
|---|---|
float, MVTSeries, or TSeries
|
Sample variance with |
Examples:
>>> import numpy as np
>>> import tsecon as tse
>>> t = tse.TSeries(tse.qq(2020, 1), np.array([1.0, 2.0, 3.0]))
>>> tse.var(t)
1.0
Source code in src/tsecon/_stats.py
varm ¶
varm(
t: TSeries,
m: float,
*,
skip_all_nans: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> Any
Sample variance with the mean m supplied externally.
Mirrors Julia's Statistics.varm. The variance counterpart of
:func:stdm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
TSeries
|
Input series. Any non-Unit frequency. |
required |
m
|
float
|
The mean to centre around. Not validated against |
required |
skip_all_nans
|
bool
|
BDaily only. If |
False
|
skip_holidays
|
bool
|
BDaily only. If |
False
|
holidays_map
|
TSeries
|
BDaily only. Boolean TSeries flagging which business days to keep. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
|
Examples:
>>> import numpy as np
>>> import tsecon as tse
>>> t = tse.TSeries(tse.qq(2020, 1), np.array([1.0, 2.0, 3.0]))
>>> tse.varm(t, 2.0)
1.0
Source code in src/tsecon/_stats.py
compare ¶
compare(
x: Any,
y: Any,
*,
name: str = "_",
showequal: bool = False,
ignoremissing: bool = False,
quiet: bool = False,
left: str = "left",
right: str = "right",
atol: float = 0.0,
rtol: float | None = None,
nans: bool = False,
trange: MITRange | None = None,
) -> CompareResult
Recursively compare x and y, returning a :class:CompareResult.
The walk dispatches over:
- :class:
~tsecon.workspace.Workspace, :class:~tsecon.mvtseries.MVTSeries, and :class:collections.abc.Mapping— treated as name-keyed containers and recursed key-by-key. Missing keys produce"missing in <left|right>"lines (unlessignoremissing=True). - :class:
~tsecon.tseries.TSeries— compared range-by-range using :func:numpy.allclosewith the givenatol/rtol/nans. Mismatched ranges count as different (unlessignoremissing=True, in which case the intersection is compared). - NumPy arrays of numbers — compared by shape + element-wise
:func:
numpy.allclose. - NumPy arrays of other dtypes — walked element-by-element.
- Scalars — compared via :func:
numpy.isclose. - Everything else — compared with
==.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
The two values to compare. |
required |
y
|
Any
|
The two values to compare. |
required |
name
|
str
|
Top-level name in the printed/structured diff ( |
'_'
|
showequal
|
bool
|
When True, also emit |
False
|
ignoremissing
|
bool
|
When True, ignore keys present in one side but not the other
(they don't print and don't affect |
False
|
quiet
|
bool
|
When True, suppress printing to stdout. The :class: |
False
|
left
|
str
|
Names used in |
'left'
|
right
|
str
|
Names used in |
'left'
|
atol
|
float
|
Tolerances forwarded to :func: |
0.0
|
rtol
|
float
|
Tolerances forwarded to :func: |
0.0
|
nans
|
float
|
Tolerances forwarded to :func: |
0.0
|
trange
|
MITRange | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
CompareResult
|
Truthy iff |
Notes
Julia's accompanying @compare macro folds into this same
function. The macro existed only to capture the input variable names
for printing; Python callers can pass left= and right= if
they want the same labelling.
Source code in src/tsecon/_various.py
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 | |
overlay ¶
Return the first non-missing value, position-by-position, from left to right.
"Missing" is defined by the dtype-appropriate typenan (NaN for
floats, iinfo(dtype).max for integers, False for booleans).
The dispatch is on the argument types — all arguments must agree on a
container family for the recursive form to apply:
- All :class:
~tsecon.tseries.TSeries— build a new TSeries over eitherrng=(when given) or the union of all input ranges (rangeof_span(*args)). For each position, the leftmost input that has a non-typenan value at that position wins. The output dtype is the NumPy promotion of all input dtypes. - All :class:
~tsecon.mvtseries.MVTSeries— return an MVTSeries over the union range and the ordered union of column names; each column is the overlay of the corresponding TSeries columns. - All Workspace / MVTSeries / Mapping — return a
:class:
~tsecon.workspace.Workspace. For each key present in any input, collect the values across inputs that have it and recurse; the recursive call may dispatch back into the TSeries / Workspace / MVTSeries / scalar paths. - Mixed types (e.g. a TSeries and a scalar) — fall through to the scalar walk: return the leftmost non-typenan value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
One or more values to overlay. At least one is required. |
()
|
rng
|
MITRange | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
A TSeries / MVTSeries / Workspace / scalar matching the input family. |
Raises:
| Type | Description |
|---|---|
TypeError
|
On empty argument list, on mixed-frequency inputs, or on
|
Source code in src/tsecon/_various.py
reindex ¶
Shift every MIT-keyed position so that old maps to new.
old_to_new is a 2-tuple (old_mit, new_mit). In MIT-value
space, every output position is the input position plus
new_mit.value - old_mit.value, and the result carries
new_mit.frequency as its frequency label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
The value to reindex. Supported types:
|
required |
old_to_new
|
tuple[MIT, MIT]
|
Pair |
required |
copy
|
bool
|
When True, force an independent values buffer for the returned
:class: |
False
|
Returns:
| Type | Description |
|---|---|
The same kind of object as ``x``, with the MIT label shifted.
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
On a malformed |
Examples:
Re-anchor a quarterly TSeries from a 2021Q1 origin to a Unit 1-based origin::
>>> from tsecon import TSeries, qq, period, Unit, reindex
>>> ts = TSeries(qq(2021, 1), [1.0, 2.0, 3.0])
>>> reindex(ts, (qq(2021, 1), period(Unit(), 1))).firstdate
1U
Source code in src/tsecon/_various.py
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 | |
extend_series ¶
extend_series(
target: FrequencyLike,
t: TSeries,
*,
direction: ExtendDirection = "both",
method: ExtendMethod = "mean",
) -> TSeries
Pad a TSeries to align with target-frequency period boundaries.
Returns a new TSeries (the input is not mutated). method="mean" fills
each padded section with the mean of the existing values that fall within
the spanned target period; method="end" repeats the nearest in-range
value (last value for the trailing pad, first in-range value for the
leading pad — matching Julia's behaviour when there is exactly one value
in the spanning period).
Source / target may be any non-Unit frequency. For a BDaily source the
in-range first/last value used by method="end", and the per-period
mean used by method="mean", are computed via
cleanedvalues(...; skip_all_nans=True) so leading / trailing NaNs do
not poison the fill (matches Julia's BDaily branch at
fconvert_helpers.jl lines 309-326).
Source code in src/tsecon/fconvert/_tseries.py
fconvert_is_cython ¶
Return True iff the Cython-compiled fconvert kernel was importable.
Useful for tests, benchmarks, and diagnostic prints — the public
:func:fconvert_tseries is implementation-agnostic. When this
returns False the same calls go through the pure-NumPy kernel
in _fconvert_kernels.py; behaviour is identical, only speed
differs.
Source code in src/tsecon/fconvert/_tseries.py
fconvert_mit ¶
fconvert_mit(
target: FrequencyLike,
mit_from: MIT,
*,
ref: Ref = "end",
round_to: RoundTo = "current",
) -> MIT
Convert mit_from to target.
For YP→YP and any Calendar-involving conversion ref selects whether to
align to the end of the source period ("end", the default) or the start
("begin"). Mirrors Julia's fconvert(F_to, MIT_from; ref=:end).
When the target is :class:BDaily, round_to controls how a date that
lands on a weekend is resolved: "current" (default) raises on
weekends, "previous" snaps to the preceding business day, "next"
snaps forward.
Examples:
>>> from tsecon import yy, Quarterly
>>> fconvert_mit(Quarterly, yy(22), ref="end")
22Q4
>>> fconvert_mit(Quarterly, yy(22), ref="begin")
22Q1
Source code in src/tsecon/fconvert/_mit.py
fconvert_parts ¶
fconvert_parts(
target: FrequencyLike,
mit_from: MIT,
*,
ref: Ref = "end",
) -> tuple[int, int, int]
Return (to_period, from_month, to_month) for the YP→YP boundary.
With ref="end" the second / third elements are the end-month-of-year
of the source / target periods; with ref="begin" they are the start
months. Mirrors Julia's fconvert_parts. YP-only; raises for any
Calendar source or target.
Source code in src/tsecon/fconvert/_mit.py
fconvert_range ¶
fconvert_range(
target: FrequencyLike,
range_from: MITRange,
*,
trim: Trim = "both",
parts: bool = False,
skip_holidays: bool = False,
holidays_map: TSeries | None = None,
) -> MITRange | tuple[int, int, int, int, int, int]
Convert range_from to target.
trim controls whether the start and / or end of the output range are
truncated when the source range begins or ends partway through a target
period. With parts=True (YP→YP only) returns the six-tuple
(fi_to_period, fi_from_start_month, fi_to_start_month, li_to_period,
li_from_end_month, li_to_end_month) used by the TSeries conversion path.
For BDaily-source lower-frequency conversion, skip_holidays /
holidays_map shift the boundary predecessor / successor past
consecutive holidays before applying the truncation check (mirrors
fconvert_mit.jl lines 239-258). skip_holidays=True consults the
global getoption('bdaily_holidays_map') map; holidays_map=t
overrides it. The kwargs are only meaningful when range_from's
frequency is BDaily and the conversion is to a lower frequency;
elsewhere they're accepted as no-ops to keep the dispatcher uniform.
Examples:
>>> from tsecon import yy, mitrange, Quarterly
>>> fconvert_range(Quarterly, mitrange(yy(22), yy(24)))
22Q1:24Q4
Source code in src/tsecon/fconvert/_mit.py
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 | |
fconvert_tseries ¶
fconvert_tseries(
arg1: FrequencyLike | Callable[..., Any],
arg2: TSeries | FrequencyLike,
arg3: TSeries | None = None,
*,
method: _AnyMethod | None = None,
ref: Ref | None = None,
**kwargs: Any,
) -> TSeries
Convert t to target frequency.
Two call shapes mirror Julia's two fconvert overloads:
fconvert_tseries(target, t, *, method=..., ref=...)— built-in aggregator / spreader.methodis one of"mean" / "sum" / "min" / "max" / "point" / "begin" / "end"for lower-frequency conversions and"const" / "even" / "linear"for higher-frequency conversions.fconvert_tseries(f, target, t, *, ref=..., **kwargs)— pass a custom callable. For lower-frequency conversionsfmust accept a single vector and return a scalar; for higher-frequency conversions it must accept(values, output_lengths)plus the keyword argumentsref=...andoutrange=....
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg1
|
FrequencyLike or Callable
|
Either the target frequency (built-in form) or the custom callable (three-positional form). |
required |
arg2
|
TSeries or FrequencyLike
|
The TSeries to convert in the built-in form, or the target frequency in the three-positional form. |
required |
arg3
|
TSeries
|
The TSeries to convert in the three-positional custom-callable form. |
None
|
method
|
str
|
Aggregator / spreader name. Lower-frequency:
|
None
|
ref
|
('begin', 'end')
|
Boundary anchor used when the source / target periods do not
align exactly. Defaults to |
"begin"
|
**kwargs
|
Any
|
Forwarded to the custom callable in the three-positional form.
For BDaily source on lower-frequency conversion, also accepts
|
{}
|
Returns:
| Type | Description |
|---|---|
TSeries
|
A new series at the |
Raises:
| Type | Description |
|---|---|
ValueError
|
Source or target is |
TypeError
|
The custom-callable form is used incorrectly, or
|
NotImplementedError
|
Conversion direction is not yet implemented. |
Examples:
Spread a Quarterly series across each quarter's three months
using the "const" (repeat) method::
>>> from tsecon import qq, TSeries, Monthly, fconvert_tseries
>>> import numpy as np
>>> q = TSeries(qq(2020, 1), np.arange(1, 11, dtype=float))
>>> m = fconvert_tseries(Monthly, q, method="const")
>>> m.firstdate
2020M1
>>> m.lastdate
2022M6
Aggregate a Monthly series to Quarterly with the mean::
>>> from tsecon import mm, Quarterly
>>> series = TSeries(mm(2020, 1), np.arange(1.0, 13.0))
>>> fconvert_tseries(Quarterly, series, method="mean").values.tolist()
[2.0, 5.0, 8.0, 11.0]
Source code in src/tsecon/fconvert/_tseries.py
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 | |
strip_tseries ¶
Return a new :class:TSeries with leading and trailing typenan trimmed.
Mirrors Julia's Base.strip(t::TSeries). The original is unchanged.
An all-typenan input returns an empty TSeries anchored at firstdate.
Source code in src/tsecon/fconvert/_helpers.py
strip_tseries_inplace ¶
Trim leading and trailing typenan entries in place; return t.
Mirrors Julia's strip!(t::TSeries).
trim_series ¶
trim_series(
target: FrequencyLike,
t: TSeries,
*,
direction: ExtendDirection = "both",
) -> TSeries
Trim a TSeries to ranges that align with target-frequency boundaries.
Returns a new TSeries restricted to the inner range produced by
fconvert(F_from, fconvert(F_to, rangeof(t), trim=direction)).
Source code in src/tsecon/fconvert/_tseries.py
endperiod ¶
Return the end-of-period offset for a frequency.
For Yearly / HalfYearly / Quarterly returns end_month; for
Weekly returns end_day; for Monthly / Daily / BDaily /
Unit returns 1.
Source code in src/tsecon/frequencies.py
is_bdaily ¶
is_daily ¶
is_halfyearly ¶
is_monthly ¶
is_quarterly ¶
is_weekly ¶
is_yearly ¶
ppy ¶
Return the (approximate) periods-per-year for the given frequency.
Exact for YPFrequency subclasses. Approximate for Daily (365),
BDaily (260), and Weekly (52). Raises ValueError for Unit.
Source code in src/tsecon/frequencies.py
prettyprint_frequency ¶
Return a short display name for a frequency.
Default-parameter frequencies print without their parameter
(Quarterly rather than Quarterly(end_month=3)); non-default ones
include the parameter in braces, matching the Julia show convention.
Source code in src/tsecon/frequencies.py
sanitize_frequency ¶
Return a concrete singleton frequency instance.
If x is already an instance, return it. If x is a frequency class
with no required arguments (or all defaults), return its default singleton.
Source code in src/tsecon/frequencies.py
lookup ¶
Return t's values at every position in keys, vectorised.
The array-of-keys companion to t[k]: while t[k] reads a
single MIT- or int-keyed position, :func:lookup reads many at
once with a single NumPy/Cython gather, avoiding the per-element
__getitem__ dispatch tax that makes the Python loop pattern
935x slower than the Julia equivalent on the M1.5 benchmark.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
TSeries
|
The series to gather values from. Not mutated. |
required |
keys
|
sequence of MIT, sequence of int, or 1-D array-like
|
The positions to read. MIT keys are frequency-checked against
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Freshly allocated 1-D array of the same length as |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any MIT key has a frequency different from |
IndexError
|
If any translated offset falls outside |
Examples:
Pick four MIT positions::
>>> from tsecon import TSeries, qq, lookup
>>> import numpy as np
>>> t = TSeries(qq(2020, 1), np.arange(100.0))
>>> lookup(t, [qq(2020, 1), qq(2020, 3), qq(2022, 1), qq(2024, 4)])
array([ 0., 2., 8., 19.])
Or pick four integer-offset positions (positional indexing,
matching t[i])::
>>> lookup(t, [0, 5, 10, 99])
array([ 0., 5., 10., 99.])
Notes
For a single key, prefer the direct indexer t[k] — it returns
a scalar without an array allocation and dispatches through the
same code path. :func:lookup is for the bulk case (e.g. 10+
keys) where vectorisation amortises the per-call setup cost.
See Also
lookup_is_cython : Check whether the compiled kernel is active.
Source code in src/tsecon/indexing.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 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 | |
lookup_is_cython ¶
Return True iff the Cython-compiled gather kernel was importable.
Useful for tests, benchmarks, and diagnostic prints — the public
:func:lookup itself is implementation-agnostic. When this returns
False the same calls go through the pure-NumPy kernel in
_indexing_kernels.py; behaviour is identical, only speed
differs.
Source code in src/tsecon/indexing.py
from_pandas ¶
from_pandas(
obj: Series | DataFrame,
*,
freq: Frequency | None = None,
wide: bool = True,
time_col: str | None = None,
name_col: str | None = None,
value_col: str | None = None,
to_workspace: bool = False,
) -> TSeries | MVTSeries | Workspace
Convert a pandas Series / DataFrame to a tsecon container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Series | DataFrame
|
A |
required |
freq
|
Frequency | None
|
Required when the time axis is a :class: |
None
|
wide
|
bool
|
When |
True
|
time_col
|
str | None
|
Optional name of the column to use as the time axis. When unset, the DataFrame index is used. |
None
|
name_col
|
str | None
|
Long-format only. Name of the column holding the per-row variable
name. Required when |
None
|
value_col
|
str | None
|
Long-format only. Name of the column holding the per-row value.
Required when |
None
|
to_workspace
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
TSeries or MVTSeries or Workspace
|
A TSeries when the input is a Series; a Workspace when
|
Source code in src/tsecon/interop/pandas.py
from_polars ¶
from_polars(
obj: DataFrame,
*,
freq: Frequency | None = None,
wide: bool = True,
time_col: str = "time",
name_col: str | None = None,
value_col: str | None = None,
to_workspace: bool = False,
) -> TSeries | MVTSeries | Workspace
Convert a polars DataFrame to a tsecon container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
DataFrame
|
A :class: |
required |
freq
|
Frequency | None
|
Required when the time column dtype is :class: |
None
|
wide
|
bool
|
When |
True
|
time_col
|
str
|
Name of the time column. Default |
'time'
|
name_col
|
str | None
|
Long-format only. |
None
|
value_col
|
str | None
|
Long-format only. Also used to decide the resulting type: a single-value-column wide DataFrame returns a TSeries; otherwise an MVTSeries is returned. |
None
|
to_workspace
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
TSeries or MVTSeries or Workspace
|
A Workspace when |
Source code in src/tsecon/interop/polars.py
to_pandas ¶
to_pandas(
obj: TSeries | MVTSeries | Workspace,
*,
index: IndexKind = "auto",
date_ref: Literal["begin", "end"] = "end",
name: str | None = None,
) -> pd.Series | pd.DataFrame
Convert a tsecon container to a pandas Series or DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
TSeries | MVTSeries | Workspace
|
A :class: |
required |
index
|
IndexKind
|
Time-axis representation. See module docstring. |
'auto'
|
date_ref
|
Literal['begin', 'end']
|
Period-anchor when |
'end'
|
name
|
str | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
Series or DataFrame
|
A Series for TSeries; a DataFrame otherwise. |
Source code in src/tsecon/interop/pandas.py
to_polars ¶
to_polars(
obj: TSeries | MVTSeries | Workspace,
*,
time_col: str = "time",
date_ref: Literal["begin", "end"] = "end",
value_col: str = "value",
) -> Any
Convert a tsecon container to a polars DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
TSeries | MVTSeries | Workspace
|
A :class: |
required |
time_col
|
str
|
Name of the emitted time column. Default |
'time'
|
date_ref
|
Literal['begin', 'end']
|
Period-anchor for non-Unit frequencies. |
'end'
|
value_col
|
str
|
Name of the value column when converting a TSeries (ignored for
MVTSeries / Workspace). Default |
'value'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Annotated as |
Source code in src/tsecon/interop/polars.py
bdaily ¶
Construct an MIT{BDaily} from a date or ISO string.
Business-daily MITs index Monday-Friday only. bias controls how a
date that lands on a weekend is resolved:
"strict"— raiseValueError."previous"— return the preceding Friday."next"— return the following Monday."nearest"— Saturday → Friday, Sunday → Monday.
When bias is not supplied, the value falls back to the global option
bdaily_creation_bias (default "strict"). Mirrors Julia's
bdaily(d::Date; bias::Symbol=getoption(:bdaily_creation_bias)).
Source code in src/tsecon/mit.py
daily ¶
frequency_of ¶
Return the frequency of an MIT, Duration, or other frequency-bearing value.
Mirrors Julia's frequencyof. Raises TypeError for values that
don't carry a frequency.
Source code in src/tsecon/mit.py
mit2yp ¶
Recover (year, period) from a YP- or Daily-/BDaily-frequency MIT.
For YPFrequency subclasses this is the canonical decomposition
int(mit) == N * year + (period - 1). For :class:Daily and
:class:BDaily it returns the year and the 1-based index of the day
within that year.
Source code in src/tsecon/mit.py
mit_to_date ¶
Convert an MIT to a :class:datetime.date.
For multi-day frequencies (Yearly, HalfYearly, Quarterly, Monthly,
Weekly) ref controls whether the end of the period (default) or
its beginning (ref="begin") is returned.
Source code in src/tsecon/mit.py
mm ¶
period ¶
qq ¶
weekly ¶
Construct an MIT{Weekly(end_day)} from a date or ISO string.
The resulting MIT identifies the week (ending on the given end_day)
that contains the provided date.
Source code in src/tsecon/mit.py
weekly_from_iso ¶
Construct an MIT{Weekly(7)} from an ISO year + week number (1..53).
Source code in src/tsecon/mit.py
year ¶
yy ¶
rangeof ¶
rangeof(
obj: object,
*,
drop: int = 0,
method: Literal["intersect", "union"] = "intersect",
) -> MITRange
Return the range of obj, optionally dropping leading/trailing periods.
Mirrors Julia's rangeof(t; drop=n) and rangeof(w; method=intersect)
(see TimeSeriesEcon.jl/src/workspaces.jl
and src/tseries.jl). The Python equivalents — :attr:TSeries.range /
:attr:MVTSeries.range properties, :meth:Workspace.rangeof,
:func:rangeof_span — remain available; this function unifies them under
a single kwarg-bearing call site that mirrors the Julia surface 1-to-1 and
is the recommended target for line-by-line tutorial / model code ports.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
A :class: |
required |
drop
|
int
|
Skip |
0
|
method
|
Literal['intersect', 'union']
|
|
'intersect'
|
Returns:
| Type | Description |
|---|---|
MITRange
|
The (possibly shrunk) range. |
Raises:
| Type | Description |
|---|---|
TypeError
|
Unsupported |
ValueError
|
|
Examples:
>>> import tsecon as ts
>>> a = ts.TSeries(ts.qq(2020, 1), [1.0, 2.0, 3.0, 4.0])
>>> ts.rangeof(a)
2020Q1:2020Q4
>>> ts.rangeof(a, drop=1)
2020Q2:2020Q4
>>> ts.rangeof(a, drop=-1)
2020Q1:2020Q3
The tutorial-1 @rec idiom ports line-by-line::
# Julia: @rec rangeof(a, drop=1) a[t] = (1-ρ)*a_ss + ρ*a[t-1]
ts.rec(ts.rangeof(a, drop=1), a, lambda t: (1 - rho) * a_ss + rho * a[t - 1])
Workspace intersection vs union:
>>> w = ts.Workspace(a=a, b=ts.TSeries(ts.qq(2020, 3), [10.0, 20.0]))
>>> ts.rangeof(w)
2020Q3:2020Q4
>>> ts.rangeof(w, method="union")
2020Q1:2020Q4
Source code in src/tsecon/mitrange.py
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 | |
rangeof_span ¶
Return the smallest forward MITRange covering all argument ranges.
All arguments must share a single frequency. Raises TypeError if
frequencies are mixed. The returned span is always forward-stepped
(step=1) regardless of the direction of the inputs.
Source code in src/tsecon/mitrange.py
hcat ¶
Concatenate MVTSeries by columns, optionally adding more via kwargs.
All positional MVTSeries must share frequency. The output range is the span of every input MVTSeries (gaps filled with the dtype's NaN). The output dtype is the common-promoted dtype across inputs and kwargs.
Column-name collisions raise ValueError — duplicates are not allowed.
Source code in src/tsecon/mvtseries.py
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 | |
rename_columns_inplace ¶
rename_columns_inplace(
mvts: MVTSeries,
new_names_or_map_or_func: list[str]
| tuple[str, ...]
| Mapping[str, str]
| Callable[[str], str]
| None = None,
*,
replace: tuple[str, str]
| list[tuple[str, str]]
| None = None,
prefix: str | None = None,
suffix: str | None = None,
) -> MVTSeries
Rename the columns of mvts in place. Mirrors Julia rename_columns!.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mvts
|
MVTSeries
|
The MVTSeries to mutate. Returned for chaining. |
required |
new_names_or_map_or_func
|
list[str] | tuple[str, ...] | Mapping[str, str] | Callable[[str], str] | None
|
One of:
|
None
|
replace
|
tuple[str, str] | list[tuple[str, str]] | None
|
|
None
|
prefix
|
str | None
|
String prepended to each column name (after |
None
|
suffix
|
str | None
|
String appended to each column name (after |
None
|
Returns:
| Type | Description |
|---|---|
MVTSeries
|
The same |
Source code in src/tsecon/mvtseries.py
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 | |
vcat ¶
Append row blocks (matrices, MVTSeries, or 2-D arrays) below mvts.
Result keeps mvts.firstdate and column names; additional rows are
appended in order. Column count must match.
Source code in src/tsecon/mvtseries.py
available_backends ¶
Return the names of installed plotting backends in preference order.
plot ¶
plot(
*series: TSeries | MVTSeries,
backend: BackendName = "auto",
trange: MITRange | None = None,
mit_loc: MitLoc = "left",
label: str | Sequence[str] | None = None,
vars: Sequence[str | tuple[str, str]] | None = None,
title: str | None = None,
xlabel: str | None = None,
ylabel: str | None = None,
legend: bool = True,
figsize: tuple[float, float] | None = None,
**kwargs: Any,
) -> Any
Plot one or more TSeries (single-axes) or MVTSeries (panel-grid) datasets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*series
|
TSeries or MVTSeries
|
One or more series of a single kind — mixing TSeries and MVTSeries in
one call raises :class: |
()
|
backend
|
('auto', 'matplotlib', 'plotly')
|
|
"auto"
|
trange
|
MITRange
|
Limit the rendered window to this range. All series must share a frequency. |
None
|
mit_loc
|
('left', 'middle', 'right')
|
Where in each period interval the value's x-coordinate sits. For
Daily / BDaily / Weekly the position is fixed at the period date
and |
"left"
|
label
|
str or sequence of str
|
One label per series (TSeries) or per dataset (MVTSeries). |
None
|
vars
|
sequence of str or (str, str)
|
For MVTSeries: select / order the variables shown. Each item is
either a column name or a |
None
|
title
|
str
|
Standard chart annotations. For panel plots, |
None
|
xlabel
|
str
|
Standard chart annotations. For panel plots, |
None
|
ylabel
|
str
|
Standard chart annotations. For panel plots, |
None
|
legend
|
bool
|
Whether to draw a legend. |
True
|
figsize
|
(float, float)
|
Matplotlib figure size (inches). The plotly backend interprets this as pixels at 100 DPI. |
None
|
Returns:
| Type | Description |
|---|---|
Figure or Figure
|
The backend's native figure object. |
Source code in src/tsecon/plotting/__init__.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
resolve_backend ¶
Resolve backend="auto" to the first available backend.
Raises :class:BackendNotAvailableError if the requested backend (or
auto with no backends installed) is not available, with a
pip-extras install hint.
Source code in src/tsecon/plotting/__init__.py
rec ¶
Compute target[t] = fn(t) for each t in rng, in order.
The Python equivalent of TimeSeriesEcon.jl's @rec macro. Each
iteration's write is committed before the next iteration runs, so
fn may reference target[t - k] (or any other series) freely:
by the time step t reads target[t - k], that period has
already been written by a prior step (assuming k >= 1 and the
recurrence is well-defined).
The target is mutated in place. Assignment to an MIT outside
target.range extends the storage via the TSeries auto-resize
rule, matching the Julia @rec behaviour.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rng
|
MITRange
|
The range to iterate over. Its frequency must match
|
required |
target
|
TSeries
|
The series being computed. Mutated in place. |
required |
fn
|
Callable[[MIT], scalar]
|
Returns the value to assign at each step. Typically a lambda
closing over |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Examples:
Fibonacci over a Unit range::
>>> from tsecon import MIT, MITRange, TSeries, rec
>>> from tsecon.frequencies import Unit
>>> import numpy as np
>>> s = TSeries(MIT(Unit(), 1), np.array([1.0, 1.0]))
>>> rec(MITRange(MIT(Unit(), 3), MIT(Unit(), 10)), s,
... lambda t: s[t - 1] + s[t - 2])
>>> [float(s[MIT(Unit(), i)]) for i in (1, 5, 10)]
[1.0, 5.0, 55.0]
AR(1) over a quarterly range, reading from a second series::
rec(rng, consumption,
lambda t: beta * consumption[t - 1] + (1 - beta) * income[t])
Backcasting over a reversed range (Julia's
@rec t=10U:-1:1U s[t] = s[t+1] - g)::
>>> s = TSeries(MIT(Unit(), 1), np.zeros(10))
>>> s[MIT(Unit(), 10)] = 20.0
>>> rec(MITRange(MIT(Unit(), 9), MIT(Unit(), 1), step=-1), s,
... lambda t: s[t + 1] - 2.0)
>>> s.values.tolist()
[2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0]
Source code in src/tsecon/recursive.py
rec_linear ¶
Compute a linear-combination recurrence over rng in place.
Specialised closed-form sibling of :func:rec for the common case
where each step's value is a fixed linear combination of earlier-
written values of the same series. Covers Fibonacci, AR(p),
arbitrary lag polynomials — the recurrences that account for ~80%
of pipeline workloads per the M1 benchmark.
The body of the loop is::
for t in rng:
target[t] = sum(coeffs[k] * target[t - lags[k]] for k in range(len(coeffs)))
Both forward (rng.step == +1) and backward (rng.step == -1)
iteration are supported. The contract on lags matches the
direction so that every read references an already-written or
initial-condition position:
- Forward (
rng.step == +1, walking fromrng.firstup torng.last): alllags[k] >= 1;targetmust contain valid values for everyrng.first - lags[k]position before the call (the initial conditions at the start). - Backward (
rng.step == -1, walking fromrng.firstdown torng.last): alllags[k] <= -1;targetmust contain valid values for everyrng.first - lags[k]position (=rng.first + |lags[k]|, the initial conditions at the end — this is backcasting).
target is resized in place to cover rng if needed (NaN
padding for new positions inside rng is overwritten by the
recurrence; positions outside rng keep whatever they had,
which is where the initial conditions live).
Dispatch
When the Cython extension tsecon._rec_kernels_cy is importable
(the typical wheel install), this function delegates to the
compiled :func:rec_linear_cython kernel — same contract,
much faster. Without the extension, the call goes through
:func:rec_linear_numpy, the pure-Python reference. Use
:func:rec_linear_is_cython to check which path is active.
Notes
rec_linear is the closed-form pure-linear-AR(p) form:
target[t] = Σ_k coeffs[k] * target[t - lags[k]] for nonzero
lags. It deliberately has no constant term and no exogenous
reads — that narrowing is what enables the Cython kernel path.
The two common near-misses:
target[t] = target[t-1] + c(random walk / cumulative sum with constant drift) is notrec_linearterritory; use :func:tsecon.undiffinstead.target[t] = β * target[t-1] + γ * y[t](AR with exogenous reads from another series) is notrec_linearterritory either; use the general :func:recwith a lambda closing over bothtargetandy.
Both near-misses raise an informative ValueError at the call
site rather than producing silent garbage — the first via the
min(lags) >= 1 contract (lags=[0] for the constant-drift
misread), the second by virtue of the closed-form signature
accepting only coeffs × lags (no second series). The
general :func:rec retains the readable nonlinear / multi-series
escape hatch; pick it whenever the recurrence body does not fit
the linear-AR(p) shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
TSeries
|
The series being computed. Must have |
required |
coeffs
|
array-like of float
|
Recurrence weights. Will be coerced to a 1-D |
required |
lags
|
array-like of int
|
Nonzero lag offsets, one per coefficient. Sign must match
|
required |
rng
|
MITRange
|
The range to compute, frequency-matched to |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
Examples:
Fibonacci over a Unit range::
>>> import numpy as np
>>> from tsecon import MIT, MITRange, TSeries, rec_linear
>>> from tsecon.frequencies import Unit
>>> s = TSeries(MIT(Unit(), 1), np.array([1.0, 1.0, 0.0, 0.0, 0.0]))
>>> rec_linear(s, [1.0, 1.0], [1, 2],
... MITRange(MIT(Unit(), 3), MIT(Unit(), 5)))
>>> s.values.tolist()
[1.0, 1.0, 2.0, 3.0, 5.0]
AR(2) recurrence over quarterly data::
rec_linear(consumption, [0.5, 0.3], [1, 2], rng)
Backcasting via a reversed range (Julia's
@rec t=10U:-1:1U s[t] = s[t+1] - g with g = 0 constant
drift becomes s[t] = s[t+1])::
rec_linear(s, [1.0], [-1],
MITRange(MIT(Unit(), 10), MIT(Unit(), 1), step=-1))
See Also
rec : General higher-order form target[t] = fn(t). Use it when
the recurrence is nonlinear or reads from series other than
target.
tsecon.undiff : Inverse of :func:tsecon.diff. Use it for
target[t] = target[t-1] + c (random walk with constant
drift) — the most common near-miss for rec_linear.
Source code in src/tsecon/recursive.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 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 | |
rec_linear_is_cython ¶
Return True iff the Cython-compiled rec_linear kernel was importable.
Useful for tests, benchmarks, and diagnostic prints — the public
:func:rec_linear itself is implementation-agnostic. When this
returns False the same calls go through the pure-NumPy kernel
in _rec_kernels.py; behaviour is identical, only speed differs.
Source code in src/tsecon/recursive.py
typenan ¶
Return the not-a-number sentinel for dtype.
For floats this is NaN; for signed and unsigned integers it is
iinfo(dtype).max; for booleans it is False. Mirrors
TimeSeriesEcon.jl's typenan (see tseries.jl).
Source code in src/tsecon/tseries.py
copyto ¶
copyto(
dst: MVTSeries,
src: Workspace,
*,
verbose: bool = False,
trange: MITRange | None = None,
) -> MVTSeries
Copy Workspace members into a pre-allocated MVTSeries in place.
Mirrors Julia's Base.copyto!(x::MVTSeries, w::AbstractWorkspace;
verbose=false, trange=rangeof(x)). For each column name in
dst.column_names, the matching src[name] :class:TSeries is
written into the destination column over the overlap of trange and
the source TSeries's range; dst._values is mutated, never replaced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dst
|
MVTSeries
|
Destination MVTSeries. Its matrix buffer is written through; storage
identity is preserved ( |
required |
src
|
Workspace
|
Source Workspace. Only members whose names appear in
|
required |
verbose
|
bool
|
When True, a single :class: |
False
|
trange
|
MITRange | None
|
Optional :class: |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dst |
MVTSeries
|
The same object passed in (enables chaining; storage identity preserved). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
IndexError
|
If |
Examples:
Tight model-simulation loop reusing the same buffer:
>>> import tsecon as ts
>>> buf = ts.MVTSeries(ts.MITRange(ts.qq(2020, 1), ts.qq(2024, 4)), ["a", "b"])
>>> for _ in range(100):
... w = _step(...) # produces a Workspace with TSeries 'a', 'b'
... ts.copyto(buf, w) # in-place; no MVTSeries reallocation
See Also
MVTSeries : the destination type. Workspace : the source type.
Source code in src/tsecon/workspace.py
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 | |