The last week of 2021 is assigned as 2022 in pandas.date_range() function, whereas, in exception of Saturday and Sunday (1st and 2nd of January), the rest of the days fall under 2021.
import pandas as pd
for x in pd.date_range(start='2021-12-01', end='2022-01-04', freq='W'):
print('date: ', x, '\tweek: ', x.week, '\tyear: ', x.year)
Output:
date: 2021-12-05 00:00:00 week: 48 year: 2021
date: 2021-12-12 00:00:00 week: 49 year: 2021
date: 2021-12-19 00:00:00 week: 50 year: 2021
date: 2021-12-26 00:00:00 week: 51 year: 2021
date: 2022-01-02 00:00:00 week: 52 year: 2022
The output makes sense, however, this doesn't work under the filtration that I am using:
df[(df['date'].year == x.year) & (df['date'].week == x.week)]
Currently this issue is fixed with a band-aid, but hoping to have it fully functioning for a next year.