Skip to content
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

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

tay
Copy link
Contributor

@tay tay commented Oct 27, 2024

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

  • I have tested my parser changes locally with poetry run test_parser "zone_key"
  • I have run pnpx prettier@2 --write . and poetry run format in the top level directory to format my changes.

Sorry, something went wrong.

@github-actions github-actions bot added parser python Pull requests that update Python code tests labels Oct 27, 2024
@tay
Copy link
Contributor Author

tay commented Oct 27, 2024

Hmm, I seem to be running into some TZ issues. Closing for the moment while I take a closer look

@tay tay closed this Oct 27, 2024
@tay tay reopened this Oct 27, 2024
@tay tay marked this pull request as ready for review October 27, 2024 19:38
@tay tay requested a review from VIKTORVAV99 as a code owner October 27, 2024 19:38
Copy link
Member

@VIKTORVAV99 VIKTORVAV99 left a 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:
Copy link
Member

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.

Copy link
Contributor Author

@tay tay Oct 31, 2024

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?

Copy link
Member

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)
Copy link
Member

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.

Comment on lines +178 to +182
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")
Copy link
Member

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.

Copy link
Member

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!

@VIKTORVAV99 VIKTORVAV99 marked this pull request as draft November 29, 2024 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser python Pull requests that update Python code tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants