Skip to content

Commit 541d263

Browse files
fix: incorrect ISO week 53 conversion when only 52 weeks exist
1 parent e557039 commit 541d263

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pandas/_libs/tslibs/strptime.pyx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,13 @@ cdef (int, int) _calc_julian_from_V(int iso_year, int iso_week, int iso_weekday)
924924

925925
correction = date(iso_year, 1, 4).isoweekday() + 3
926926
ordinal = (iso_week * 7) + iso_weekday - correction
927+
928+
if iso_week == 53:
929+
now = date.fromordinal(date(iso_year, 1, 1).toordinal() + ordinal - iso_weekday)
930+
jan_4th = date(iso_year+1, 1, 4)
931+
if (jan_4th - now).days < 7:
932+
raise ValueError(f"Week 53 does not exist in ISO year {iso_year}.")
933+
927934
# ordinal may be negative or 0 now, which means the date is in the previous
928935
# calendar year
929936
if ordinal < 1:

0 commit comments

Comments
 (0)