Try running this code. You will notice that week_of_month returns negative values.
import pendulum
from datetime import datetime
problematic_dates = ['2021-01-30 00:00:00',
'2021-01-29 00:00:00',
'2021-01-28 00:00:00',
'2021-01-27 00:00:00',
'2021-01-26 00:00:00',
'2021-01-25 00:00:00',
'2021-01-23 00:00:00',
'2021-01-22 00:00:00',
'2021-01-21 00:00:00',
'2021-01-20 00:00:00',
'2021-01-19 00:00:00',
'2021-01-18 00:00:00',
'2021-01-15 00:00:00',
'2021-01-14 00:00:00',
'2021-01-13 00:00:00',
'2021-01-12 00:00:00',
'2021-01-11 00:00:00',
'2021-01-09 00:00:00',
'2021-01-08 00:00:00',
'2021-01-07 00:00:00',
'2021-01-06 00:00:00',
'2021-01-05 00:00:00',
'2021-01-04 00:00:00',
'2019-12-31 00:00:00',
'2019-12-30 00:00:00']
for x in problematic_dates:
x = datetime.strptime(x, '%Y-%m-%d %H:%M:%S')
week_num_of_the_month = pendulum.parse((x.strftime('%Y') + x.strftime('%m') + x.strftime('%d'))).week_of_month
print(f'{x}: {week_num_of_the_month}')
2021-01-30 00:00:00: -48
2021-01-29 00:00:00: -48
2021-01-28 00:00:00: -48
2021-01-27 00:00:00: -48
2021-01-26 00:00:00: -48
2021-01-25 00:00:00: -48
2021-01-23 00:00:00: -49
2021-01-22 00:00:00: -49
2021-01-21 00:00:00: -49
2021-01-20 00:00:00: -49
2021-01-19 00:00:00: -49
2021-01-18 00:00:00: -49
2021-01-15 00:00:00: -50
2021-01-14 00:00:00: -50
2021-01-13 00:00:00: -50
2021-01-12 00:00:00: -50
2021-01-11 00:00:00: -50
2021-01-09 00:00:00: -51
2021-01-08 00:00:00: -51
2021-01-07 00:00:00: -51
2021-01-06 00:00:00: -51
2021-01-05 00:00:00: -51
2021-01-04 00:00:00: -51
2019-12-31 00:00:00: -46
2019-12-30 00:00:00: -46
Issue
Try running this code. You will notice that
week_of_monthreturns negative values.OUTPUT: