Skip to content

remove FUZZY setting #794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions dateparser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def __init__(self, tokens, settings):
self.time = lambda: time_parser(self._token_time)
continue

results = self._parse(type, token, settings.FUZZY, skip_component=skip_component)
results = self._parse(type, token, skip_component=skip_component)
for res in results:
if len(token) == 4 and res[0] == 'year':
skip_component = 'year'
Expand Down Expand Up @@ -395,15 +395,6 @@ def _results(self):
self._set_relative_base()

time = self.time() if self.time is not None else None

if self.settings.FUZZY:
attr_truth_values = []
for attr in ['day', 'month', 'year', 'time']:
attr_truth_values.append(getattr(self, attr, False))

if not any(attr_truth_values):
raise ValueError('Nothing date like found')
Comment on lines -399 to -405
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the purpose of fuzzy is to only return a date if all those elements can be extracted for that date. Is that not a scenario that makes sense? Or is it that it does not work? (i.e. does the test also pass if it is set to False?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Gallaecio, there are several reasons to remove this setting:

  1. Is not documented.
  2. Only applies to absolute-parser.
  3. Has a confusing name ("when Fuzzy is True then raise an error if the date is not complete" does this make sense for you? The semanthics are really bad.
  4. We have the STRICT_PARSING setting which is documented and works better as well as REQUIRE_PARTS, that can be used with the same purpose.


params = self._get_datetime_obj_params()

if time:
Expand Down Expand Up @@ -510,7 +501,7 @@ def parse(cls, datestring, settings):

return dateobj, period

def _parse(self, type, token, fuzzy, skip_component=None):
def _parse(self, type, token, skip_component=None):

def set_and_return(token, type, component, dateobj, skip_date_order=False):
if not skip_date_order:
Expand Down Expand Up @@ -541,10 +532,7 @@ def parse_number(token, skip_component=None):
except ValueError:
pass
else:
if not fuzzy:
raise ValueError('Unable to parse: %s' % token)
else:
return []
raise ValueError('Unable to parse: %s' % token)

def parse_alpha(token, skip_component=None):
type = 1
Expand All @@ -567,10 +555,7 @@ def parse_alpha(token, skip_component=None):
except:
pass
else:
if not fuzzy:
raise ValueError('Unable to parse: %s' % token)
else:
return []
raise ValueError('Unable to parse: %s' % token)

handlers = {0: parse_number, 1: parse_alpha}
return handlers[type](token, skip_component)
Expand Down
1 change: 0 additions & 1 deletion dateparser_data/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
'RELATIVE_BASE': False,
'DATE_ORDER': 'MDY',
'PREFER_LOCALE_DATE_ORDER': True,
'FUZZY': False,
'STRICT_PARSING': False,
'RETURN_TIME_AS_PERIOD': False,
'PARSERS': default_parsers,
Expand Down
11 changes: 0 additions & 11 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,17 +435,6 @@ def test_error_is_raised_when_year_part_missing(self, date_string):
self.given_settings(settings={'REQUIRE_PARTS': ['year']})
self.then_error_is_raised_when_date_is_parsed(date_string)

@parameterized.expand([
param(date_string="Januar"),
param(date_string="56341819"),
param(date_string="56341819 Febr"),
])
def test_error_is_raised_when_invalid_dates_given_when_fuzzy(self, date_string):
self.given_parser()
self.given_settings(settings={'FUZZY': True})
self.when_date_is_parsed(date_string)
self.then_error_was_raised(ValueError, ['Nothing date like found'])

def given_parser(self):
self.parser = _parser

Expand Down