Commit 386f4dc
committed
BUG:
This fixes GH#62602 where `date_range` failed for nonexistent times during
DST transitions due to `Timestamp.normalize` not handling `ambiguous` and
`nonexistent` parameters.
Changes:
- Updated `Timestamp.normalize` (in `_libs/tslibs/timestamps.pyx`):
* Added `ambiguous` and `nonexistent` keyword arguments (defaulting to "raise").
* Passed these parameters to `tz_localize` to properly handle DST-related
ambiguous and nonexistent timestamps.
- Updated type stubs in `timestamps.pyi` to reflect the new method signature.
- Extended `_maybe_normalize_endpoints` (in `core/arrays/datetimes.py`):
* Added support for `ambiguous` and `nonexistent` parameters.
* Updated internal normalization calls to propagate these parameters.
- Updated `DatetimeArray._generate_range` logic to ensure consistent propagation
of `ambiguous` and `nonexistent` through `_maybe_normalize_endpoints` both
before and after timezone handling.
With these changes, `date_range` now correctly handles cases where normalization
intersects DST transitions, preserving expected behavior and avoiding
`NonExistentTimeError` or `AmbiguousTimeError` exceptions.
Co-authored-by: Mohamed Sobhy <[email protected]>pandas.date_range() raises NonExistentTimeError despite nonexistent="shift_forward" when crossing DST boundaries1 parent 10102e6 commit 386f4dc
File tree
3 files changed
+21
-7
lines changed- pandas
- _libs/tslibs
- core/arrays
3 files changed
+21
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
195 | 199 | | |
196 | 200 | | |
197 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1308 | 1308 | | |
1309 | 1309 | | |
1310 | 1310 | | |
1311 | | - | |
| 1311 | + | |
1312 | 1312 | | |
1313 | 1313 | | |
1314 | 1314 | | |
| |||
1346 | 1346 | | |
1347 | 1347 | | |
1348 | 1348 | | |
1349 | | - | |
| 1349 | + | |
1350 | 1350 | | |
1351 | 1351 | | |
1352 | 1352 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
447 | 447 | | |
448 | 448 | | |
449 | 449 | | |
450 | | - | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
451 | 453 | | |
452 | 454 | | |
453 | 455 | | |
| |||
466 | 468 | | |
467 | 469 | | |
468 | 470 | | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
469 | 475 | | |
470 | 476 | | |
471 | 477 | | |
| |||
2878 | 2884 | | |
2879 | 2885 | | |
2880 | 2886 | | |
2881 | | - | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
| 2890 | + | |
| 2891 | + | |
2882 | 2892 | | |
2883 | 2893 | | |
2884 | 2894 | | |
2885 | | - | |
| 2895 | + | |
2886 | 2896 | | |
2887 | 2897 | | |
2888 | | - | |
| 2898 | + | |
2889 | 2899 | | |
2890 | 2900 | | |
2891 | 2901 | | |
| |||
0 commit comments