Skip to content

separate absolute-time from no-spaces-time - #786

Merged
noviluni merged 4 commits into
scrapinghub:masterfrom
noviluni:separate_absolute-time_from_no-spaces-time
Sep 21, 2020
Merged

noviluni merged 4 commits into
scrapinghub:masterfrom
noviluni:separate_absolute-time_from_no-spaces-time

Conversation

@noviluni

@noviluni noviluni commented Sep 11, 2020 •

Copy link
Copy Markdown
Contributor

Fixes: #751, fixes #713, #769, reduce false positives in: #582

I separated the no-spaces-time parser from the absolute-time parser. I made some changes in the tests as it was expected to return None when finding invalid inputs but it should return an empty date_data ({'date_obj': None, 'period': ...}) or raising an exception and I preferred the second approach.

From what I did I thought that we should improve the parsers API, so I opened a new issue: #785

@codecov

codecov Bot commented Sep 11, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #786 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #786      +/-   ##
==========================================
- Coverage   98.37%   98.37%   -0.01%     
==========================================
  Files         231      231              
  Lines        2522     2520       -2     
==========================================
- Hits         2481     2479       -2     
  Misses         41       41              
Impacted Files Coverage Δ
dateparser/date.py 99.58% <100.00%> (+<0.01%) ⬆️
dateparser/date_parser.py 100.00% <100.00%> (ø)
dateparser/parser.py 99.01% <100.00%> (-0.02%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a18cc09...c2096ae. Read the comment docs.

Comment thread dateparser/parser.py
Comment on lines -164 to +162
return
raise ValueError('Unable to parse date from: %s' % datestring)

datestring = datestring.replace(':', '')
if not datestring:
return
raise ValueError("Empty string")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this change the current behaviour? Is it a breaking change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As explained, in the PR description: "I made some changes in the tests as it was expected to return None when finding invalid inputs but it should return an empty date_data ({'date_obj': None, 'period': ...}) or raising an exception and I preferred the second approach". This decision was made to make it behave more similar to the absolute-time parser.

About the "breaking change", this PR has been tagged as it. The full implementation is a breaking change.

Comment thread dateparser_data/settings.py Outdated
'relative-time',
'custom-formats',
'absolute-time',
'no-spaces-time',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should probably be documented in docs/usage.rst (the other parsers are listed there).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are totally right! I added it!

@noviluni

noviluni commented Sep 17, 2020 •

Copy link
Copy Markdown
Contributor Author

Hey @Gallaecio @skyuchukov-bp , thank you for the feedback!

I added some information in the docs.

On the other hand, as I have been able to play around with only the no-spaces-time parser, I've seen that it returns non-expected results in more than 90% of situations, so I decided to exclude the no-spaces-time parser from the default parsers. This parser is causing a lot of side-effect issues and excluding it from the default parsers will fix all of them.

Of course, this is a breaking change, but it's ok as we are going to release a new major version. People will be able to use it by doing:

    >>> from dateparser_data.settings import default_parsers
    >>> dateparser.parse('2016020417:10', settings={'PARSERS': default_parsers + ['no-spaces-time']})

Let me know what you think about this point.


This will fix the well-known issue with the STRICT_PARSING and single years, for example.

>>> dateparser.parse('2017', settings={'STRICT_PARSING': True})

@noviluni

Copy link
Copy Markdown
Contributor Author

I also checked the #582 issue and it fixes a lot of the cases:

For example, for this string (created from the second comment in #582):

text = '32° 34’S and 123° and 6005 and 000 and of 629 and >21 and 3533 and 538400'

Last released version:

>>> search_dates(text)                                                      
[('32° 34’S', datetime.datetime(2020, 9, 17, 10, 57, 48, 787596)),
 ('123°', datetime.datetime(1900, 1, 1, 1, 2, 3)),
 ('6005', datetime.datetime(6005, 1, 1, 0, 0)),
 ('000', datetime.datetime(1900, 1, 1, 0, 0)),
 ('629', datetime.datetime(1900, 1, 1, 6, 2, 9)),
 ('>21', datetime.datetime(1900, 1, 21, 0, 0)),
 ('3533', datetime.datetime(3533, 1, 21, 0, 0)),
 ('538400', datetime.datetime(8400, 5, 3, 0, 0))]

>>> search_dates(text, settings={'STRICT_PARSING': True})
[('32° 34’S', datetime.datetime(2020, 9, 17, 10, 58, 28, 836995)),
 ('123°', datetime.datetime(1900, 1, 1, 1, 2, 3)),
 ('6005', datetime.datetime(2000, 6, 5, 0, 0)),
 ('000', datetime.datetime(1900, 1, 1, 0, 0)),
 ('629', datetime.datetime(1900, 1, 1, 6, 2, 9)),
 ('>21', datetime.datetime(1900, 1, 1, 2, 1)),
 ('3533', datetime.datetime(2033, 3, 5, 0, 0)),
 ('538400', datetime.datetime(8400, 5, 3, 0, 0))]

this PR:

>>> search_dates(text)
[('32° 34’S', datetime.datetime(2020, 9, 17, 11, 4, 21, 207745)),
 ('6005', datetime.datetime(6005, 9, 17, 0, 0)),
 ('>21', datetime.datetime(6005, 9, 21, 0, 0)),
 ('3533', datetime.datetime(3533, 9, 21, 0, 0))]

>>> search_dates(text, settings={'STRICT_PARSING': True})
[('32° 34’S', datetime.datetime(2020, 9, 17, 11, 4, 58, 313809))]

@noviluni
noviluni requested a review from Gallaecio September 21, 2020 09:37
@Gallaecio

Copy link
Copy Markdown
Contributor

Looks good to me.

@noviluni
noviluni merged commit 4749262 into scrapinghub:master Sep 21, 2020
@noviluni noviluni added this to the 1.1.0 milestone Sep 21, 2020
@noviluni

Copy link
Copy Markdown
Contributor Author

thank you guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split a separate "no-spaces" parser setting off of the current "absolute-time" one Is there a way to ignore numbers unless they are epochs?

3 participants