-
Notifications
You must be signed in to change notification settings - Fork 976
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
Remove arrow from GSO (MY-WM) parser #7355
base: master
Are you sure you want to change the base?
Conversation
Hmm, I seem to be running into some TZ issues. Closing for the moment while I take a closer look |
Seems to be related to: spulec/freezegun#553
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments about readability and such but otherwise it seems to function as expected.
@@ -61,7 +71,12 @@ def fetch_consumption( | |||
logger: Logger = getLogger(__name__), | |||
) -> list: | |||
"""Request the power consumption (in MW) of a given zone.""" | |||
date_string = arrow.get(target_datetime).to(TIMEZONE).format("DD/MM/YYYY") | |||
if target_datetime: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should check that the target datetime has a timezone or not, not that it exists. If someone is manually calling the parser with a datetime it would most likely be called without a timezone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, when I invoke the parser from the command line (poetry run test_parser "MY-WM" consumption
), it seems that the target_datetime argument is None
. Also, the type of target_datetime is nullable.
Can you explain what you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can call the parser with poetry run test_parser "MY-MW" consumption --target_datetime="2024-01-01"
for example.
Then the target datetime is defined but the timezone is not.
@@ -61,7 +71,12 @@ def fetch_consumption( | |||
logger: Logger = getLogger(__name__), | |||
) -> list: | |||
"""Request the power consumption (in MW) of a given zone.""" | |||
date_string = arrow.get(target_datetime).to(TIMEZONE).format("DD/MM/YYYY") | |||
if target_datetime: | |||
target_datetime_tz = target_datetime.astimezone(TIMEZONE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This naming also don't convey what it is.
I'd use something like target_datetime_with_local_timezone
it don't matter much if it's long or not as long as it's clear.
if target_datetime: | ||
target_datetime_tz = target_datetime.astimezone(TIMEZONE) | ||
else: | ||
target_datetime_tz = datetime.now(TIMEZONE) | ||
date_string = target_datetime_tz.strftime("%d/%m/%Y") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is doing the same as above, I'd extract them both to a new function.
parsers/test/test_GSO.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice with some added tests!
Issue
#6135
Description
Remove arrow usages from the GSO (West Malaysia) parser. Also backfills snapshot tests for the consumption and production parser.
Preview
Double check
poetry run test_parser "zone_key"
pnpx prettier@2 --write .
andpoetry run format
in the top level directory to format my changes.