scrapinghub / scrapinghub/dateparser
Hijri Calendar: list index out of range
Open
Nobody has claimed this yet.
Type: Bug
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 520
- Avg merge
- 22h 56m
- Merged PRs (30d)
- 6
Description
Date: 10 Safar 1004 Hijri to Gregorian
HijriCalendar('02-10-1004').get_date()
In [28]: HijriCalendar('02-10-1004').get_date()
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-28-2c9dd191b1d9> in <module>()
----> 1 HijriCalendar('02-10-1004').get_date()
/usr/local/lib/python2.7/dist-packages/dateparser/calendars/__init__.pyc in get_date(self)
22 def get_date(self):
23 try:
---> 24 date_obj, period = self.parser.parse(self.source, settings)
25 return {'date_obj': date_obj, 'period': period}
26 except ValueError:
/usr/local/lib/python2.7/dist-packages/dateparser/calendars/__init__.pyc in parse(cls, datestring, settings)
137 def parse(cls, datestring, settings):
138 datestring = cls.to_latin(datestring)
--> 139 return super(non_gregorian_parser, cls).parse(datestring, settings)
/usr/local/lib/python2.7/dist-packages/dateparser/parser.pyc in parse(cls, datestring, settings)
453 tokens = tokenizer(datestring)
454 po = cls(tokens.tokenize(), settings)
--> 455 dateobj = po._results()
456
457 # correction for past, future if applicable
/usr/local/lib/python2.7/dist-packages/dateparser/parser.pyc in _results(self)
370 microsecond=time.microsecond))
371
--> 372 return self._get_datetime_obj(**params)
373
374 def _correct_for_time_frame(self, dateobj):
/usr/local/lib/python2.7/dist-packages/dateparser/calendars/__init__.pyc in _get_datetime_obj(self, **params)
84 month = params['month']
85 if (
---> 86 not(0 < day <= self.calendar_converter.month_length(year, month)) and
87 not(self._token_day or hasattr(self, '_token_weekday'))
88 ):
/usr/local/lib/python2.7/dist-packages/dateparser/calendars/hijri_parser.pyc in month_length(cls, year, month)
26 iln = (ii * 12) + 1 + (im - 1)
27 i = iln - 16260
---> 28 mcjdn = id + UmalqurraArray.ummalqura_dat[i - 1] - 1
29 index = UmalqurraArray.get_index(mcjdn)
30 ml = UmalqurraArray.ummalqura_dat[index] - UmalqurraArray.ummalqura_dat[index - 1]
IndexError: list index out of range
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce HijriCalendar('02-10-1004').get_date() and trace the failure through the parser to calendars/hijri_parser.pyc, especially month_length and UmalqurraArray. Determine the intended behavior for this date and add regression coverage so the conversion no longer raises IndexError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100