-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat: Support both "iso" and "iso:strict" format options for dt.to_string
#19840
base: main
Are you sure you want to change the base?
feat: Support both "iso" and "iso:strict" format options for dt.to_string
#19840
Conversation
Excuse me, but why do you insist on joining in space instead of ISO 8601 format? I think one of the following changes is necessary:
|
I think I explained it reasonably clearly, but I'll try again to better clarify ;) It is called "T" being considered mandatory by the ISO spec is a new development, and only true for ISO 8601-1:2019 and later - for earlier versions of the spec (which dates back some 36 years to 1988) the space is fine. The space version is preferred as it is the more human-readable of the two, and is still considered to be an ISO format by all tools, libraries, etc (as for the majority of the spec's existence space was considered a valid separator). As two examples (amongst many), both the Python standard library and the from datetime import datetime
datetime.fromisoformat("2020-10-08 10:30:45")
# datetime(2020, 10, 8, 10, 30, 45)
import dateutil
dtm = dateutil.parser.isoparse("2020-10-08 10:30:45")
# datetime(2020, 10, 8, 10, 30, 45) ...and the standard library allows for a space when exporting back to ISO (it defaults to "T", but space is so common that an option to allow it is integrated directly into the ISO format function): dtm.isoformat(" ")
# '1980-08-10 00:10:20' I do not consider these usages (either in But, to fully conform with the most recent version of the spec, I introduce |
Thanks for the clarification! This SO thread was also informative. The space is certainly used in this ISO's 2017 post.
That said, given that it is now 2024, it is questionable whether the default I don't think there is any equivalence between a function like At least |
A follow-up to enable stricter ISO formatting for
dt.to_string()
with Datetime.See #19697 (comment) for the rationale/details 🤔
TLDR
"iso"
: (what we have now) each component is ISO, joined with a space (this was valid ISO 8601 for the majority of the spec's lifetime, but now falls under RFC 3339 - see the comments below for more explanation/details, and the "Spec Arcana" section)."iso:strict"
: (new) same as the above, but with a "T" separator between date/time instead of a space; this conforms to the latest ISO spec amendment, ISO 8601-1:2019).Spec Arcana
Making the "T" mandatory for Datetimes was an amendment made (around five years ago) in ISO 8601-1:2019. Consequently you will see both forms (with a space or with a "T") used widely, with both being referred to as "ISO", depending on the date of implementation and which version of the spec was being targeted.
Also
to_string
docstring for Series and DataFrame with additional explanation and examples.Example