-
Notifications
You must be signed in to change notification settings - Fork 86
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
update the dependency and temporal filter for python_cmr 0.10.0 #520
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
979c982
directly use python_cmr's temporal
itcarroll 50b46d3
add lxml-html-clean
itcarroll 463c2f3
better documentaion
itcarroll 998bcf0
bump python-cmr
itcarroll 4dccdf7
deps change with python-cmr update
itcarroll e4ed258
syntax
itcarroll 5dc411a
lint
itcarroll 2d7a8d2
remove conda-forge workaround
itcarroll a9a4801
Merge branch 'main' into temporal
itcarroll c7a311a
poetry lock without updates
itcarroll 977231b
test utc offset
itcarroll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,7 +1,6 @@ | ||||||||||
import datetime as dt | ||||||||||
from inspect import getmembers, ismethod | ||||||||||
|
||||||||||
import dateutil.parser as parser | ||||||||||
import requests | ||||||||||
from typing_extensions import ( | ||||||||||
Any, | ||||||||||
|
@@ -409,45 +408,29 @@ def daac(self, daac_short_name: str) -> Self: | |||||||||
@override | ||||||||||
def temporal( | ||||||||||
self, | ||||||||||
date_from: Optional[Union[str, dt.datetime]] = None, | ||||||||||
date_to: Optional[Union[str, dt.datetime]] = None, | ||||||||||
date_from: Optional[Union[str, dt.date]] = None, | ||||||||||
date_to: Optional[Union[str, dt.date]] = None, | ||||||||||
exclude_boundary: bool = False, | ||||||||||
) -> Self: | ||||||||||
"""Filter by an open or closed date range. Dates can be provided as datetime | ||||||||||
objects or ISO 8601 formatted strings. Multiple ranges can be provided by | ||||||||||
successive calls to this method before calling execute(). | ||||||||||
"""Filter by an open or closed date range. Dates can be provided as date objects | ||||||||||
or ISO 8601 strings. Multiple ranges can be provided by successive method calls. | ||||||||||
|
||||||||||
???+ Tip | ||||||||||
Giving either `datetime.date(YYYY, MM, DD)` or `"YYYY-MM-DD"` as the `date_to` | ||||||||||
parameter includes that entire day (i.e. the time is set to `23:59:59`). | ||||||||||
Using `datetime.datetime(YYYY, MM, DD)` is different, because `datetime.datetime` | ||||||||||
objects have `00:00:00` as their built-in default. | ||||||||||
itcarroll marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
Parameters: | ||||||||||
date_from (String or Datetime object): earliest date of temporal range | ||||||||||
date_to (String or Datetime object): latest date of temporal range | ||||||||||
exclude_boundary (Boolean): whether or not to exclude the date_from/to in | ||||||||||
the matched range. | ||||||||||
date_from (String or Date): start of temporal range | ||||||||||
date_to (String or Date): end of temporal range | ||||||||||
exclude_boundary (Boolean): whether to exclude the date_from and date_to in the matched range. | ||||||||||
|
||||||||||
Returns: | ||||||||||
self | ||||||||||
|
||||||||||
Raises: | ||||||||||
ValueError: `date_from` or `date_to` is a non-`None` value that is | ||||||||||
neither a datetime object nor a string that can be parsed as a datetime | ||||||||||
object; or `date_from` and `date_to` are both datetime objects (or | ||||||||||
parsable as such) and `date_from` is after `date_to`. | ||||||||||
""" | ||||||||||
DEFAULT = dt.datetime(1979, 1, 1) | ||||||||||
if date_from is not None and not isinstance(date_from, dt.datetime): | ||||||||||
try: | ||||||||||
date_from = parser.parse(date_from, default=DEFAULT).isoformat() + "Z" | ||||||||||
except Exception: | ||||||||||
print("The provided start date was not recognized") | ||||||||||
date_from = "" | ||||||||||
|
||||||||||
if date_to is not None and not isinstance(date_to, dt.datetime): | ||||||||||
try: | ||||||||||
date_to = parser.parse(date_to, default=DEFAULT).isoformat() + "Z" | ||||||||||
except Exception: | ||||||||||
print("The provided end date was not recognized") | ||||||||||
date_to = "" | ||||||||||
|
||||||||||
return super().temporal(date_from, date_to, exclude_boundary) | ||||||||||
super().temporal(date_from, date_to, exclude_boundary) | ||||||||||
return self | ||||||||||
|
||||||||||
|
||||||||||
class DataGranules(GranuleQuery): | ||||||||||
|
@@ -817,46 +800,29 @@ def debug(self, debug: bool = True) -> Self: | |||||||||
@override | ||||||||||
def temporal( | ||||||||||
self, | ||||||||||
date_from: Optional[Union[str, dt.datetime]] = None, | ||||||||||
date_to: Optional[Union[str, dt.datetime]] = None, | ||||||||||
date_from: Optional[Union[str, dt.date]] = None, | ||||||||||
date_to: Optional[Union[str, dt.date]] = None, | ||||||||||
Comment on lines
+803
to
+804
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
exclude_boundary: bool = False, | ||||||||||
) -> Self: | ||||||||||
"""Filter by an open or closed date range. | ||||||||||
"""Filter by an open or closed date range. Dates can be provided as date objects | ||||||||||
or ISO 8601 strings. Multiple ranges can be provided by successive method calls. | ||||||||||
|
||||||||||
Dates can be provided as a datetime objects or ISO 8601 formatted strings. | ||||||||||
Multiple ranges can be provided by successive calls to this method before | ||||||||||
calling execute(). | ||||||||||
???+ Tip | ||||||||||
Giving either `datetime.date(YYYY, MM, DD)` or `"YYYY-MM-DD"` as the `date_to` | ||||||||||
parameter includes that entire day (i.e. the time is set to `23:59:59`). | ||||||||||
Using `datetime.datetime(YYYY, MM, DD)` is different, because `datetime.datetime` | ||||||||||
objects have `00:00:00` as their built-in default. | ||||||||||
|
||||||||||
Parameters: | ||||||||||
date_from: earliest date of temporal range | ||||||||||
date_to: latest date of temporal range | ||||||||||
exclude_boundary: whether to exclude the date_from/to in the matched range | ||||||||||
date_from (String or Date): start of temporal range | ||||||||||
date_to (String or Date): end of temporal range | ||||||||||
exclude_boundary (Boolean): whether to exclude the date_from and date_to in the matched range. | ||||||||||
|
||||||||||
Returns: | ||||||||||
self | ||||||||||
|
||||||||||
Raises: | ||||||||||
ValueError: `date_from` or `date_to` is a non-`None` value that is | ||||||||||
neither a datetime object nor a string that can be parsed as a datetime | ||||||||||
object; or `date_from` and `date_to` are both datetime objects (or | ||||||||||
parsable as such) and `date_from` is after `date_to`. | ||||||||||
""" | ||||||||||
DEFAULT = dt.datetime(1979, 1, 1) | ||||||||||
if date_from is not None and not isinstance(date_from, dt.datetime): | ||||||||||
try: | ||||||||||
date_from = parser.parse(date_from, default=DEFAULT).isoformat() + "Z" | ||||||||||
except Exception: | ||||||||||
print("The provided start date was not recognized") | ||||||||||
date_from = "" | ||||||||||
|
||||||||||
if date_to is not None and not isinstance(date_to, dt.datetime): | ||||||||||
try: | ||||||||||
date_to = parser.parse(date_to, default=DEFAULT).isoformat() + "Z" | ||||||||||
except Exception: | ||||||||||
print("The provided end date was not recognized") | ||||||||||
date_to = "" | ||||||||||
|
||||||||||
return super().temporal(date_from, date_to, exclude_boundary) | ||||||||||
""" | ||||||||||
super().temporal(date_from, date_to, exclude_boundary) | ||||||||||
return self | ||||||||||
|
||||||||||
@override | ||||||||||
def version(self, version: str) -> Self: | ||||||||||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I know it's not necessary or even correct since datetime is a subclass of date, but I think from a documentation standpoint this will be clearer to users.
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.
Currently the type hint does not effect the documentation, because the docstring includes a "type". Do you want that part removed from the docstring?
If type hints are being included to help developers, then I would want them to be technically correct. If type hints are being included to help users ... well, I fell like that's a little lazy actually. Users don't benefit a whole lot from "dt.date" without knowing what "dt" is. And do they know what "Optional[Union[...]]" means? Relying on auto documentation is nice ... if it's good documentation.
You are welcome to modify however you think its best.
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.
Personally, when type annotations are provided, I drop type information from the docstrings. Otherwise, it's all too easy for the docstrings to become out of sync with the type annotations, leading to confusion, misinformation, and frustration. Modern doc generators, including mkdocs, will make use of the type annotations to put such information in the docs. Doc generators should also use canonical names for things as well, meaning that even though the code may refer to the
datetime
module asdt
, the docs will show the namedatetime
, so there's no need for the reader to know about any aliasing within the code.