Skip to content

Commit

Permalink
Merge pull request #358 from hellohaptik/fix_date_detector_typerror
Browse files Browse the repository at this point in the history
fix(date-detection): Fix TypeError when comparing None mm with int
  • Loading branch information
chiragjn authored Apr 17, 2020
2 parents 47b424a + b7920dc commit 809841d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 42 deletions.
32 changes: 14 additions & 18 deletions ner_v1/detectors/temporal/date/date_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1305,17 +1305,15 @@ def _gregorian_month_day_format(self, date_list=None, original_list=None):
dd = pattern[2]
probable_mm = pattern[1]
mm = self.__get_month_index(probable_mm)
if dd:
if dd and mm:
dd = int(dd)
if mm:
mm = int(mm)
if self.now_date.month > mm:
yy = self.now_date.year + 1
elif self.now_date.day > dd and self.now_date.month == mm:
yy = self.now_date.year + 1
else:
yy = self.now_date.year
if mm:
if self.now_date.month > mm:
yy = self.now_date.year + 1
elif self.now_date.day > dd and self.now_date.month == mm:
yy = self.now_date.year + 1
else:
yy = self.now_date.year
date_dict = {
'dd': int(dd),
'mm': int(mm),
Expand Down Expand Up @@ -1362,17 +1360,15 @@ def _gregorian_day_month_format(self, date_list=None, original_list=None):
dd = pattern[1]
probable_mm = pattern[2]
mm = self.__get_month_index(probable_mm)
if dd:
if dd and mm:
dd = int(dd)
if mm:
mm = int(mm)
if self.now_date.month > mm:
yy = self.now_date.year + 1
elif self.now_date.day > dd and self.now_date.month == mm:
yy = self.now_date.year + 1
else:
yy = self.now_date.year
if mm:
if self.now_date.month > mm:
yy = self.now_date.year + 1
elif self.now_date.day > dd and self.now_date.month == mm:
yy = self.now_date.year + 1
else:
yy = self.now_date.year
date_dict = {
'dd': int(dd),
'mm': int(mm),
Expand Down
46 changes: 22 additions & 24 deletions ner_v2/detectors/temporal/date/en/date_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ def _gregorian_day_month_year_format(self, date_list=None, original_list=None):
if not pattern[3] and self.timezone.localize(datetime.datetime(year=yy, month=mm, day=dd)) \
< self.now_date:
yy += 1
except:
return date_list, original_list
except Exception:
continue

date = {
'dd': int(dd),
Expand Down Expand Up @@ -377,8 +377,8 @@ def _gregorian_month_day_year_format(self, date_list=None, original_list=None):
if not pattern[3] and self.timezone.localize(datetime.datetime(year=yy, month=mm, day=dd)) \
< self.now_date:
yy += 1
except:
return date_list, original_list
except Exception:
continue

date = {
'dd': int(dd),
Expand Down Expand Up @@ -698,8 +698,9 @@ def _gregorian_month_day_with_ordinals_year_format(self, date_list=None, origina
if not yy1 and not yy2 and self.timezone.localize(datetime.datetime(year=yy, month=mm, day=dd)) \
< self.now_date:
yy += 1
except:
return date_list, original_list
except Exception:
continue

date = {
'dd': int(dd),
'mm': int(mm),
Expand Down Expand Up @@ -747,17 +748,16 @@ def _gregorian_month_day_format(self, date_list=None, original_list=None):
dd = pattern[2]
probable_mm = pattern[1]
mm = self.__get_month_index(probable_mm)
if dd:
if dd and mm:
dd = int(dd)
if mm:
mm = int(mm)
if self.now_date.month > mm:
yy = self.now_date.year + 1
elif self.now_date.day > dd and self.now_date.month == mm:
yy = self.now_date.year + 1
else:
yy = self.now_date.year
if mm:
if self.now_date.month > mm:
yy = self.now_date.year + 1
elif self.now_date.day > dd and self.now_date.month == mm:
yy = self.now_date.year + 1
else:
yy = self.now_date.year

date_dict = {
'dd': int(dd),
'mm': int(mm),
Expand Down Expand Up @@ -804,17 +804,15 @@ def _gregorian_day_month_format(self, date_list=None, original_list=None):
dd = pattern[1]
probable_mm = pattern[2]
mm = self.__get_month_index(probable_mm)
if dd:
if dd and mm:
dd = int(dd)
if mm:
mm = int(mm)
if self.now_date.month > mm:
yy = self.now_date.year + 1
elif self.now_date.day > dd and self.now_date.month == mm:
yy = self.now_date.year + 1
else:
yy = self.now_date.year
if mm:
if self.now_date.month > mm:
yy = self.now_date.year + 1
elif self.now_date.day > dd and self.now_date.month == mm:
yy = self.now_date.year + 1
else:
yy = self.now_date.year
date_dict = {
'dd': int(dd),
'mm': int(mm),
Expand Down

0 comments on commit 809841d

Please sign in to comment.