You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeError: can't compare offset-naive and offset-aware datetimes #679
I found a workaround: #736 but it seems that the core problem is the self.now. It's also the causing of some errors related to the multithreading: #441
I am working on a project that utilizes this search functionality, and I get the same error. Do you know whether there is a fix right around the corner? Otherwise, I’m happy to work on one. I just don’t want to submit an unnecessary pull if there’s gonna be a fix soon.
Hi @jhawgs, sorry, I haven't time to spend on this. Please, go ahead!
I created this PR: #736, you can continue from that or submit a new/different PR. The only requirement is to add tests to check that nothing is broken and the coverage is still the same after merging the PR.
I've been working on the bug, but I don't believe that I am familiar enough with the code as I would need to be to put together a comprehensive fix. I did, however, find that the error occurs when running a function that only seems to be useful when one has set the PREFER_DATES_FROM setting to something other than the default. Because I am not using this functionality, I am simply bypassing the function call. To do this I comment out the following line in parser.py:
dateobj = po._correct_for_time_frame(dateobj)
This may or may not be an option for anybody having the problem, but I certainly do not recommend it as a long term fix.
Also, I found some weird behavior that I don't think is expected, but I might be wrong. When running LeptoFlare's example, the parser tries to retain certain states across dates. This portion of the example:
>>> search_dates("""May 2020 ... June 2020 ... 2023 ... January UTC""")
Specifically it assumes that "January UTC" is in 2023 instead of reverting back to the current year and assuming that it refers to January of either 2021 or 2020. This might be expected behavior when leaving PREFER_DATES_FROM as the default "current_period," but when looking at the code that should change the date based on a new setting of "past" or "future," it looks like the only possibilities would be 2022 or 2023. This bug occurs in the same function call that I commented out, which suggests that anybody looking for a comprehensive fix for either issue should start at:
dateobj = po._correct_for_time_frame(dateobj) in parser.py.
Here's another string type that has the same error thrown: [02.10.21]
Granted this is ambiguous as to whether it's February 10, 2021 or October 2, 2021, however the same can't compare offset-naive and offset-aware datetimes is thrown.
EDIT:
This is so strange! If I just try that string ([02.10.21]) search_dates works fine. However, if I try it after I get the error, I then get the same error. See log:
The issue here is not one of multi-threading or self.now. The issue is that self.now gets set to a timezone unaware (e.g. naive) time. I'm investigating a fix here.
Activity
cysabi commentedon May 14, 2020
noviluni commentedon Jul 1, 2020
Related to: #491
noviluni commentedon Jul 1, 2020
I've been investigating this. It is a weird bug, as the next works:
But when joining the dates it doesn't work:
This is because of the
self.nowof theparser.py.I found a workaround: #736 but it seems that the core problem is the
self.now. It's also the causing of some errors related to the multithreading: #441I will check it when having a moment.
jhawgs commentedon Oct 10, 2020
I am working on a project that utilizes this search functionality, and I get the same error. Do you know whether there is a fix right around the corner? Otherwise, I’m happy to work on one. I just don’t want to submit an unnecessary pull if there’s gonna be a fix soon.
noviluni commentedon Oct 11, 2020
Hi @jhawgs, sorry, I haven't time to spend on this. Please, go ahead!
I created this PR: #736, you can continue from that or submit a new/different PR. The only requirement is to add tests to check that nothing is broken and the coverage is still the same after merging the PR.
Thanks!
jhawgs commentedon Oct 15, 2020
I've been working on the bug, but I don't believe that I am familiar enough with the code as I would need to be to put together a comprehensive fix. I did, however, find that the error occurs when running a function that only seems to be useful when one has set the PREFER_DATES_FROM setting to something other than the default. Because I am not using this functionality, I am simply bypassing the function call. To do this I comment out the following line in parser.py:
dateobj = po._correct_for_time_frame(dateobj)This may or may not be an option for anybody having the problem, but I certainly do not recommend it as a long term fix.
Also, I found some weird behavior that I don't think is expected, but I might be wrong. When running LeptoFlare's example, the parser tries to retain certain states across dates. This portion of the example:
>>> search_dates("""May 2020 ... June 2020 ... 2023 ... January UTC""")gets the following dates:
2020-05-14 00:00:00 2020-06-14 00:00:00 2023-01-14 00:00:00 2023-01-14 00:00:00Specifically it assumes that "January UTC" is in 2023 instead of reverting back to the current year and assuming that it refers to January of either 2021 or 2020. This might be expected behavior when leaving PREFER_DATES_FROM as the default "current_period," but when looking at the code that should change the date based on a new setting of "past" or "future," it looks like the only possibilities would be 2022 or 2023. This bug occurs in the same function call that I commented out, which suggests that anybody looking for a comprehensive fix for either issue should start at:
dateobj = po._correct_for_time_frame(dateobj)in parser.py.SimplicityGuy commentedon Feb 11, 2021
Here's another string type that has the same error thrown:
[02.10.21]Granted this is ambiguous as to whether it's February 10, 2021 or October 2, 2021, however the same
can't compare offset-naive and offset-aware datetimesis thrown.EDIT:
This is so strange! If I just try that string (
[02.10.21])search_datesworks fine. However, if I try it after I get the error, I then get the same error. See log:SimplicityGuy commentedon Feb 13, 2021
The issue here is not one of multi-threading or
self.now. The issue is thatself.nowgets set to a timezone unaware (e.g. naive) time. I'm investigating a fix here.SimplicityGuy commentedon Feb 13, 2021
Fixed in PR #881. Please take a look.
Reducing cyclomatic complexity of search and addressing offset awaren…
noviluni commentedon Feb 19, 2021
PR #881 has been merged, so we can close this issue now :)
use dateparser from master due to a bug in it, scrapinghub/dateparser…