8000 #175 Restore timezone aware datetime objects when time specified with Z (zulu) by chrgro · Pull Request #186 · python-metar/python-metar · GitHub < 8000 link rel="alternate icon" class="js-site-favicon" type="image/png" href="https://github.githubassets.com/favicons/favicon.png">
[go: up one dir, main page]

Skip to content

Conversation

@chrgro
Copy link
Contributor
@chrgro chrgro commented Jan 3, 2025

The fix for issue #175 , commit 7dfbe07, changes the returned datetime objects to no longer have timezone information. This makes it harder to use this library as it becomes arguably harder to compare times against other datetime objects that do have timezone information. The timezone of a METAR is well defined (at least if the Z char is present), so it makes sense in my eyes that the returned object should be timezone aware.

@chrgro
Copy link
Contributor Author
chrgro commented Jan 3, 2025

I also had to modify the CI setup as newer setuptools versions conflict with something in the setup.py or related code. I wasn't quite able to rootcause it. I opted to just fix an older setuptool versions, as the least intrusive change. A bigger and more longerm solution is probably to move away from setuptools and use a pyproject.toml file instead. That's outside the scope of this PR.

if utcdelta:
self._utcdelta = utcdelta
else:
self._utcdelta = datetime.datetime.now() - self._now
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what this self._utcdelta piece of code did. It does not seem to be referenced anywhere else in the codebase. I kept the argument to not break backwards compatibility, but removed the dead code.

__email__ = "pollard@alum.mit.edu"

__version__ = "1.11.0"
__version__ = "1.12.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the version being bumped?

Copy link
Contributor Author
@chrgro chrgro Jan 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I assumed that had to be done do make a new PyPI release. I'm unfamiliar with whether that's commonly done separately. Now removed from this PR.

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 88.94%. Comparing base (fba07d3) to head (e8f6a3a).

Files with missing lines Patch % Lines
metar/Metar.py 60.00% 4 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #186      +/-   ##
==========================================
+ Coverage   88.62%   88.94%   +0.31%     
==========================================
  Files           4        4              
  Lines        1046     1040       -6     
==========================================
- Hits          927      925       -2     
+ Misses        119      115       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@akrherz
Copy link
Collaborator
akrherz commented Jan 4, 2025

I am on the fence on this. Presently, we have an unambiguous situation of always having a naive datetime returned. This can be important for downstream consuming apps that can't handle a mix of naive and not naive. I'd rather leave the datetime as naive, but keep your _zulu bool, for those to use downstream. Others have thoughts?

@akrherz
Copy link
Collaborator
akrherz commented Jan 4, 2025

move away from setuptools and use a pyproject.toml file instead.

Indeed, as was found with #184, a PR that does this would be very appreciated!

@chrgro
Copy link
Contributor Author
chrgro commented Jan 4, 2025

Has anyone seen a METAR report with a timestamp that isn't suffixed with Z? I've never encountered one in my flying career, I've only seen ones with Z suffix. I am unable to follow the README links to any of the METAR specs, so the best reference I've found is this random PDF https://www.weather.gov/media/wrh/mesowest/metar_decode_key.pdf , which on page 5 says "DATE/TIME All dates and times in UTC using a 24-hour clock; two-digit date and four-digit time; always appended with Z to indicate UTC.". It seems unlikely to be allowed, but I opted to keep that support in this PR since the original regexp had the Z as optional. I agree that its a bit messy that the library now can return both.

It's important to note that v1.10.0 of this library always returned UTC tzinfo datetime. Only in v1.11.0 was this (accidentally?) changed as part of removing the deprecated utcnow() function, see 7dfbe07 .

This relates to the fix for issue python-metar#175, commit 7dfbe07, which
accidentally changes the datetime objects from python-metar
from timezone aware to non-timezone-aware.

A new field ._zulu is added to distinguish whether the Z char is
used as suffix of the timestamp in the METAR, but the timestamp
is always assumed to be in UTC.
@chrgro
Copy link
Contributor Author
chrgro commented Jan 5, 2025

I've updated the pull request to now always return UTC timezone datetime object, returning the behavior to the v1.10.0 revision. Thoughts?

The patch is also rebased on top of the pyproject.toml change in #187.

@akrherz
Copy link
Collaborator
akrherz commented Jan 7, 2025

I don't think your assessment of 7dfbe07 is right

>>> import datetime
>>> datetime.datetime.utcnow().tzinfo is None
True

@akrherz
Copy link
Collaborator
akrherz commented Jan 7, 2025

For the record, I am sort of in favor of this change, but I suspect it will cause downstream folks grief.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0