-
Notifications
You must be signed in to change notification settings - Fork 149
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
Cannot use ISO 8601 date format #1696
Comments
Thanks for the report. Can reproduce, and looked under the hood : This command fails with your inputs : from datetime import datetime
datetime.strptime("2024-W40", "%G-W%V").date()
This seems to be a limitation of datetime as mentioned in this SO question Excerpts :
It looks like dateutil is already a dependency from frictionless, so I don't see any drawback to using dateutil instead. Just to be sure, for your use case, do you see any inconvenience to store "2024-W40" as the first day of this week internally ? I guess that if it is only for validation then it should not matter. |
Hi, |
You mean, if the format is set to "default" ? I'm going to need a little time to think before replying, while I parse the XML documentation linked in the table schema specification myself! Actual code already uses dateutil in this case with additional asserts and a comment, but I do not know if something has changed between v1 and v2 : if self.format == "default":
# Guard against shorter formats supported by dateutil
assert cell[16] == ":"
assert len(cell) >= 19
cell = platform.dateutil_parser.isoparse(cell) |
Hi Pierre, |
I looked a little bit closer into this issue :
However, all things considered, I'll say that this isn't a bug but a feature : "%G-W%V" is actually not a valid date format, as it indicates an entire week. I have no access to the ISO8601 standard to check whether it makes such a distinction. However Additionnaly, the Table Schema specification is very explicit about this :
So If you need to validate this format, I would suggest you preprocess your data before validation (adding |
@pierrecamilleri, @SimonScholler For a ISO 8601 date/datetime, you can use import datetime as dt
>>> dt.date.fromisoformat("2024-W40")
datetime.date(2024, 9, 30)
>>> dt.datetime.fromisoformat("2024-W40")
datetime.datetime(2024, 9, 30, 0, 0) As mentioned in the docs, the inverse of this is import datetime as dt
>>> dt.date.fromisoformat("2024-W40").isocalendar()
datetime.IsoCalendarDate(year=2024, week=40, weekday=1) Finally, bringing it all back together in import datetime as dt
year, week, weekday = dt.date.fromisoformat("2024-W40").isocalendar()
>>> dt.datetime.strptime(f"{year}-W{week}-{weekday}", "%G-W%V-%u").date()
datetime.date(2024, 9, 30) |
Hi,
I have a schema that contains a field 'date' which also specifies an ISO 8601 date format:
When doing validation on a data file, I get the following error.
It work when I use a non-ISO date format such as "%Y-W%W", but using this would be semantically wrong.
Am I missing something here or is this a known issue? Is there a workaround?
Thank you and kind regards
Simon
The text was updated successfully, but these errors were encountered: