scrapinghub / scrapinghub/dateparser

Not detecting date when adding words to date string

Open
#926 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
520
Avg merge
22h 56m
Merged PRs (30d)
6

Description

Hi,
I am testing dateparser and it seems that it may not work in some cases if the string containing the date contains additional words.

In the following example, I added the term "fr" to the string (randomly chosen), and tested DateDataParser in Spanish and English. While the latter worked, the former did not.

Spanish
IN
dt = "fr 18 Mayo 2021"
ddp = DateDataParser(languages=['es'])
ddp.get_date_data(dt, date_formats=["fr %d %B %Y"])
OUT
DateData(date_obj=None, period='day', locale=None)
English
IN
dt = "fr 18 May 2021"
ddp = DateDataParser(languages=['en'])
ddp.get_date_data(dt, date_formats=["fr %d %B %Y"])
OUT
DateData(date_obj=datetime.datetime(2021, 5, 18, 0, 0), period='day', locale=None)

Any thoughts on this? I am using v1.0.0


UPDATE

After searching a bit more I realised that you state

The input string it's a valid date and it doesn't contain any other words or numbers.

I understand this if no format is given. However, if a format is given, where the added word is included (like in the example), perhaps it should work?

For now I'll be using:

from datetime import datetime
import locale

locale.setlocale(locale.LC_TIME, "es_ES")
dt = "fr 18 Mayo 2021"
datetime.strptime(dt, "fr %d %B %Y")

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the DateDataParser.get_date_data reproducer using Spanish and the format "fr %d %B %Y", then compare it with the working English example. Trace how the supplied date format and Spanish month name are handled; done means the Spanish input returns the expected 18 May 2021 date.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.