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

Type annotate the temporal module #604

Merged
merged 17 commits into from
Sep 27, 2024
Merged

Type annotate the temporal module #604

merged 17 commits into from
Sep 27, 2024

Conversation

mfisher87
Copy link
Member

@mfisher87 mfisher87 commented Sep 10, 2024

Important

To be merged only after merging #598 and then rebasing

Annotating this module was pretty quick! No typeguards or ignores needed.

Copy link

github-actions bot commented Sep 10, 2024

Binder 👈 Launch a binder notebook on this branch for commit 7f92261

I will automatically update this comment whenever this PR is modified

Binder 👈 Launch a binder notebook on this branch for commit e805f01

Binder 👈 Launch a binder notebook on this branch for commit 7b57037

Binder 👈 Launch a binder notebook on this branch for commit 224ca75

Binder 👈 Launch a binder notebook on this branch for commit df965c2

Binder 👈 Launch a binder notebook on this branch for commit 7751e26

Binder 👈 Launch a binder notebook on this branch for commit d037e11

Binder 👈 Launch a binder notebook on this branch for commit 094d3f0

Binder 👈 Launch a binder notebook on this branch for commit 97a5544

Binder 👈 Launch a binder notebook on this branch for commit b0eb2b9

Binder 👈 Launch a binder notebook on this branch for commit af907f3

@mfisher87 mfisher87 added the review::quick This change should not require more than 10 minutes to review label Sep 10, 2024
Copy link

codecov bot commented Sep 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.79%. Comparing base (b7e07bf) to head (af907f3).
Report is 1 commits behind head on development.

Additional details and impacted files
@@               Coverage Diff               @@
##           development     #604      +/-   ##
===============================================
- Coverage        71.78%   66.79%   -4.99%     
===============================================
  Files               38       36       -2     
  Lines             3133     3078      -55     
  Branches           599      593       -6     
===============================================
- Hits              2249     2056     -193     
- Misses             773      933     +160     
+ Partials           111       89      -22     

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

@@ -261,14 +271,18 @@ def validate_date_range_date(date_range, start_time=None, end_time=None):
return _start, _end


def validate_date_range_dict(date_range, start_time=None, end_time=None):
def validate_date_range_dict(
date_range: dict[str, dt.datetime],
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
date_range: dict[str, dt.datetime],
date_range: dict[str, dt.datetime, dt.date],

Copy link
Member Author

@mfisher87 mfisher87 Sep 25, 2024

Choose a reason for hiding this comment

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

Good catch! I see what you're going for, the correct way to write that would be dict[str, Union[dt.datetime, dt.date]], which means "a dict with str keys, and values which can be either dt.datetime or dt.date."

Dates and datetimes are related, so I think we can equivalently annotate dict[str, dt.date]:

>>> import datetime as dt
>>> datetime = dt.datetime.now()
>>> date = dt.datetime.now().date()
>>> datetime
datetime.datetime(2024, 9, 25, 12, 47, 38, 861853)
>>> date
datetime.date(2024, 9, 25)
>>> isinstance(datetime, dt.date)
True
>>> isinstance(datetime, dt.datetime)
True
>>> isinstance(date, dt.date)
True
>>> isinstance(date, dt.datetime)
False

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Based on your description, it should be:
dict[str, Union[str, dt.date]] since str is also a valid input for the values.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see, thank you!

Copy link
Member Author

@mfisher87 mfisher87 Sep 26, 2024

Choose a reason for hiding this comment

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

97a5544 - I should have read the doctests more closely 🔔

Copy link
Member

Choose a reason for hiding this comment

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

icepyx/core/query.py Outdated Show resolved Hide resolved
icepyx/core/temporal.py Outdated Show resolved Hide resolved
Base automatically changed from typecheck-apiformatting to development September 25, 2024 23:51
icepyx/core/temporal.py Outdated Show resolved Hide resolved
Co-authored-by: Jessica Scheick <[email protected]>
Copy link
Member

@JessicaS11 JessicaS11 left a comment

Choose a reason for hiding this comment

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

thanks for adding types to this module, @mfisher87!

@mfisher87
Copy link
Member Author

mfisher87 commented Sep 27, 2024

Thanks for the thorough review 🙇

I don't understand why the unit tests aren't running here. Re-opening PR to trigger.

@mfisher87 mfisher87 closed this Sep 27, 2024
@mfisher87 mfisher87 reopened this Sep 27, 2024
@mfisher87 mfisher87 merged commit 628ad8f into development Sep 27, 2024
8 of 9 checks passed
@mfisher87 mfisher87 deleted the typecheck-temporal branch September 27, 2024 17:07
@JessicaS11
Copy link
Member

JessicaS11 commented Sep 27, 2024

I don't understand why the unit tests aren't running here. Re-opening PR to trigger.

#618

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review::quick This change should not require more than 10 minutes to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants