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

Better DATES #259

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion xscen/catutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ def _parse_level(text: str) -> str:
return text


@register_parse_type("datebounds", regex=r"(([\d]+(\-[\d]+)?)|fx)", group_count=3)
# Minimum 4 digits for a date (a single year). Maximum is, in theory, YYYYMMDDHHMMSS so 14.
@register_parse_type(
"datebounds", regex=r"(([\d]{4,15}(\-[\d]{4,15})?)|fx)", group_count=3
)
def _parse_datebounds(text: str) -> tuple[str, str]:
"""Parse helper to translate date bounds, used in the special DATES field."""
if "-" in text:
Expand Down
2 changes: 1 addition & 1 deletion xscen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _parse_date(date, fmts):
except (KeyError, ValueError):
try:
date = pd.Timestamp(date)
except pd._libs.tslibs.parsing.DateParseError:
except (pd._libs.tslibs.parsing.DateParseError, ValueError):
date = pd.NaT
elif isinstance(date, cftime.datetime):
for n in range(3):
Expand Down