Commit 6280cd9
authored
Fix OSError when displaying Polars DataFrames with old timestamps on Windows (#7477)
**Fixes #7469**
### Problem
When displaying a Polars DataFrame with timestamps before the Unix epoch
(1970) or very old dates (e.g., 1902-01-01), marimo would crash on
Windows with:
```
OSError: [Errno 22] Invalid argument
```
This occurred in the `_get_bin_values_temporal()` function when calling
`datetime.fromtimestamp()` to convert millisecond timestamps back to
datetime/date objects for histogram bin visualization.
### Root Cause
`datetime.fromtimestamp()` has platform-specific limitations on Windows:
- Cannot handle negative timestamps (dates before 1970-01-01)
- Cannot handle very old dates that are out of the platform's supported
range
- This is a known Windows limitation with timestamp conversions
### Solution
Modified `_get_bin_values_temporal()` in `narwhals_table.py` to use a
more robust approach:
- Wrapped `fromtimestamp()` calls in try-except blocks to catch
`OSError`, `OverflowError`, and `ValueError`
- Added fallback logic using `datetime.timedelta`: `epoch +
timedelta(seconds=timestamp)`
- This approach works for any date within Python's datetime range (years
1-9999) regardless of platform1 parent fd5c750 commit 6280cd9
File tree
2 files changed
+80
-2
lines changed- marimo/_plugins/ui/_impl/tables
- tests/_plugins/ui/_impl/tables
2 files changed
+80
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
616 | 616 | | |
617 | 617 | | |
618 | 618 | | |
619 | | - | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
620 | 632 | | |
621 | | - | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
622 | 649 | | |
623 | 650 | | |
624 | 651 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1315 | 1315 | | |
1316 | 1316 | | |
1317 | 1317 | | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
1318 | 1369 | | |
1319 | 1370 | | |
1320 | 1371 | | |
| |||
0 commit comments