Commit c2e6818
[polars] Sort joined frame by Date so yearly returns are correct
`read_data_polars` builds the combined price table with a chain of
`join(..., how='full', coalesce=True)` calls. Polars does not guarantee
join output row order: keys present on only one side are appended to the
end of the frame rather than slotted into place.
The Exercise 2 solution then takes `drop_nulls().first()/.last()` within
`group_by('year')`, which assumes rows are date-ordered. With the index
data that assumption breaks, because the Nikkei trades a different
holiday calendar from the US indices, so Nikkei-only dates land at the
end of the frame. The US columns are null on those appended rows and so
`drop_nulls()` skips them, which confines the damage to the Nikkei
column and let it pass review unnoticed.
Verified against Yahoo Finance data: the fix changes 51 of 204 yearly
return cells, all in the Nikkei column. Several were badly wrong and
some had the wrong sign (2017 read -6.42% against an actual +16.18%,
2020 read +3.79% against +18.27%). The code ran green throughout and
printed plausible numbers, which is the worst failure mode for a
published lecture.
Also in this commit:
- Add a note on join ordering, which reinforces the lecture's own
"no index, no automatic alignment" theme and is a genuine gotcha
when migrating from pandas.
- Drop an orphaned `[^mung]` footnote carried over from pandas.md. The
word "munging" appears nowhere in this lecture, so the definition
rendered as nothing at all.
- Cite the official Polars migration guide for the no-index discussion
instead of a personal Medium post, for authority and longevity.
- Drop the unused `(pd-series)=` label from pandas.md. Nothing
references it, so the PR now touches a single lecture.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 1b7c680 commit c2e6818
2 files changed
Lines changed: 11 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| |||
658 | 658 | | |
659 | 659 | | |
660 | 660 | | |
661 | | - | |
| 661 | + | |
662 | 662 | | |
663 | 663 | | |
664 | 664 | | |
665 | 665 | | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
666 | 675 | | |
667 | 676 | | |
668 | 677 | | |
| |||
796 | 805 | | |
797 | 806 | | |
798 | 807 | | |
799 | | - | |
800 | | - | |
| |||
0 commit comments