scrapinghub / dateparser

python parser for human readable dates
BSD 3-Clause "New" or "Revised" License
2.55k stars 465 forks source link

Different result without settings and when passing empty/unrelated settings with languages=[] #430

Open lopuhin opened 6 years ago

lopuhin commented 6 years ago
In [22]: dateparser.parse('08 listopad 2017', languages=[], settings={'RELATIVE_BASE': datetime(2018, 6, 28)})

In [23]: dateparser.parse('08 listopad 2017', languages=[], settings={})

In [24]: dateparser.parse('08 listopad 2017', languages=[])
Out[24]: datetime.datetime(2017, 11, 8, 0, 0)

So only the last call works correctly, while passing empty or unrelated settings makes it fail. Also it seems that the issue is with languages=[], passing languages=None works the same in all cases.

wRAR commented 6 years ago

It's because of this code in dateparser.parse(). If settings is not passed, the default parser is used whether languages is [], None or other false value, but if settings is passed, languages=[] is used. And dateparser.languages.loader.LocaleDataLoader._load_data() handles [] and None differently.

So it depends on the intended meaning of languages=[]. If it indeed should mean that no languages is supported then the default parser should not be used when languages=[] is passed. Otherwise LocaleDataLoader should be fixed to check for emptiness an not just for None.