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
Fixing current_period logic for weekdays #1118
Conversation
Could you extend tests to cover the change? |
I apologize, I'm quite new to using github. Could you expand on what more I need to do, and how/where to do it? |
Please, have a look at https://dateparser.readthedocs.io/en/latest/contributing.html#get-started, which covers running tests locally with Once you have run the tests locally, you will see if your change introduced unexpected changes. If not, the idea is that you extend the test code in the |
I have looked at the contributing guidelines, but they seem a bit sparse on explanations. Perhaps that's just my lack of knowledge at play though. Tox fails due to fasttext failing. I've never dealt with tox before, but I know I do have fasttext installed, so I'm not sure why this is occurring. Also, I'm not sure which test file I should be editing, how to format my tests, or how how to actually do the testing with the test file. I just wanted to propose a small logic change, but perhaps I've stepped into territory out of my league at the moment. I'm content with maintaining my change on my fork for personal use for now. If someone else would like to take over if they believe my changes are worth implementing, please do. If I should move this to an issue as suggested feedback instead, let me know. Thanks. |
Hello, I've since gotten more familiar with the technology being used here and can run You mention "if your change introduced unexpected changes" so I'd like clarification on how to proceed with my changes before making a new PR. On a fresh clone of the repo with no changes made I get 9 failed tests. With my changes proposed here I get 30 failed, so 21 caused by my changes. Looking just at those, it makes sense they fail. That would be expected with how my change modifies the functionality in these 21 cases. Example:
The current implementation of My updated implementation of . |
Almost or identical? If identical, it sounds like you are fixing a bug. If almost, it sound like we need to have extra keys to cover a behavior that is neither past nor current. |
Almost identical. Here's a concrete example. import dateparser
import datetime
settings_one={
'PREFER_DATES_FROM': 'past',
'RELATIVE_BASE': datetime.datetime(2024, 2, 7)
}
settings_two={
'PREFER_DATES_FROM': 'current_period',
'RELATIVE_BASE': datetime.datetime(2024, 2, 7)
}
# RELATIVE_BASE is Wednesday February 7th, 2024
print("PREFER_DATES_FROM: past")
print(dateparser.parse('Monday', settings=settings_one))
print(dateparser.parse('Tuesday', settings=settings_one))
print(dateparser.parse('Wednesday', settings=settings_one))
print(dateparser.parse('Thursday', settings=settings_one))
print(dateparser.parse('Friday', settings=settings_one))
print(dateparser.parse('Saturday', settings=settings_one))
print(dateparser.parse('Sunday', settings=settings_one))
print()
print("PREFER_DATES_FROM: current_period")
print(dateparser.parse('Monday', settings=settings_two))
print(dateparser.parse('Tuesday', settings=settings_two))
print(dateparser.parse('Wednesday', settings=settings_two))
print(dateparser.parse('Thursday', settings=settings_two))
print(dateparser.parse('Friday', settings=settings_two))
print(dateparser.parse('Saturday', settings=settings_two))
print(dateparser.parse('Sunday', settings=settings_two)) This outputs the following: PREFER_DATES_FROM: past
2024-02-05 00:00:00
2024-02-06 00:00:00
2024-01-31 00:00:00
2024-02-01 00:00:00
2024-02-02 00:00:00
2024-02-03 00:00:00
2024-02-04 00:00:00
PREFER_DATES_FROM: current_period
2024-02-05 00:00:00
2024-02-06 00:00:00
2024-02-07 00:00:00
2024-02-01 00:00:00
2024-02-02 00:00:00
2024-02-03 00:00:00
2024-02-04 00:00:00 As you can see, the results are identical except for the day of the relative base.
Currently My argument is that Now you bring up the point this could instead be implemented as a new key rather than changing the |
You say you don’t get why To me it seems we need to look into I am brain dumping out loud here. The point is, I agree that output seems wrong, I am just not sure what the right fixes should be. |
It outputs the 6th because the relative base is the 7th. The middle of the week, Wednesday. |
I've just tested it with months as per your reply above and the results are interesting. Whereas for days of the week import dateparser
import datetime
settings_one={
'PREFER_DATES_FROM': 'past',
'RELATIVE_BASE': datetime.datetime(2024, 3, 1)
}
settings_two={
'PREFER_DATES_FROM': 'current_period',
'RELATIVE_BASE': datetime.datetime(2024, 3, 1)
}
# RELATIVE_BASE is Friday March 1st, 2024
print("PREFER_DATES_FROM: past")
print(dateparser.parse('January', settings=settings_one))
print(dateparser.parse('February', settings=settings_one))
print(dateparser.parse('March', settings=settings_one))
print(dateparser.parse('April', settings=settings_one))
print(dateparser.parse('May', settings=settings_one))
print(dateparser.parse('June', settings=settings_one))
print(dateparser.parse('July', settings=settings_one))
print()
print("PREFER_DATES_FROM: current_period")
print(dateparser.parse('January', settings=settings_two))
print(dateparser.parse('February', settings=settings_two))
print(dateparser.parse('March', settings=settings_two))
print(dateparser.parse('April', settings=settings_two))
print(dateparser.parse('May', settings=settings_two))
print(dateparser.parse('June', settings=settings_two))
print(dateparser.parse('July', settings=settings_two)) PREFER_DATES_FROM: past
2024-01-01 00:00:00
2024-02-01 00:00:00
2024-03-01 00:00:00
2023-04-01 00:00:00
2023-05-01 00:00:00
2023-06-01 00:00:00
2023-07-01 00:00:00
PREFER_DATES_FROM: current_period
2024-01-01 00:00:00
2024-02-01 00:00:00
2024-03-01 00:00:00
2024-04-01 00:00:00
2024-05-01 00:00:00
2024-06-01 00:00:00
2024-07-01 00:00:00 Here, the relative base is March of 2024. Per how it works with days, it would be expected that "March" parses as March of 2023, but it is instead inclusive and parses as March of 2024. |
When the
current_period
setting is used the current period for weekdays should be treated as the current week.Test Date:
2023-01-09 00:00:00
(Monday)Test Input:
dateparser.parse("Thursday", settings={'PREFER_DATES_FROM': 'current_period'})
Current Output:
2023-01-05 00:00:00
(Previous Week)Desired Output:
2023-01-12 00:00:00
(Current Week)