pandas dt.month is ~2.34× slower than polars dt.month() for extracting the month from a date
The date column is already parsed on both sides before timing starts.
Result
| Run | pandas dt.month | polars dt.month() | Ratio |
|---|---|---|---|
| Run 1 | 12.94 | 5.62 | 2.30× |
| Run 2 | 13.27 | 5.67 | 2.34× |
| Run 3 | 15.49 | 6.43 | 2.41× |
Spread over 3 runs: pandas dt.month CV 10.0% / polars dt.month() CV 7.7% / ratio CV 2.2%
The two calls
df['dt'].dt.month df['dt'].dt.month() Conditions
Dates span 2024-01-01 to 2024-12-28.
Where this number does not apply
Parsing the strings inside the timed block would change the result completely.
Reproduce
cd bench && python run.py --run 1 --out ../data/run1.json