Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
ENH: Timedelta isoformat #15136
Conversation
|
fyi the parsing issue is here: #11375 |
| + """ | ||
| + Format Timedelta as ISO 8601 Duration like | ||
| + `P[n]Y[n]M[n]DT[n]H[n]M[n]S`, where the `[n]`s are replaced by the | ||
| + values for that duration. |
| +`ISO8601 duration`_ | ||
| + | ||
| +.. _ISO601 duration: https://en.wikipedia.org/wiki/ISO_8601 | ||
| + |
jreback
added Enhancement Output-Formatting Timedelta
labels
Jan 15, 2017
jreback
added this to the
0.20.0
milestone
Jan 15, 2017
|
lgtm minor did comment |
| + result = td.isoformat() | ||
| + expected = 'P0DT0H0M0.000000123S' | ||
| + self.assertEqual(result, expected) | ||
| + |
jreback
Jan 15, 2017
Contributor
add a test for NaT (which i think should just be nan), similar to what we do for Timestamp
TomAugspurger
Jan 15, 2017
Contributor
Good call. How about NaT to match Timestamp?
In [24]: pd.Timestamp('NaT').isoformat()
Out[24]: 'NaT'
In [25]: pd.Timedelta('NaT').isoformat()
Out[25]: 'NaT'|
Thanks for the review. Added the |
codecov-io
commented
Jan 15, 2017
•
Current coverage is 86.23% (diff: 100%)@@ master #15136 diff @@
==========================================
Files 145 145
Lines 51352 54034 +2682
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 43932 46598 +2666
- Misses 7420 7436 +16
Partials 0 0
|
|
lgtm. merge on pass. |
This was referenced Jan 15, 2017
|
Do we need to note that a |
|
@jorisvandenbossche does a @pwalsh does that sound right to you? |
|
Yeah, it is not really clear from the wiki page. It depends on how the 'days' are interpreted, but from "But keep in mind that "PT36H" is not the same as "P1DT12H" when switching from or to Daylight saving time." I would conclude that the days are also relative and not absolute (not 1D == 24H), and I think for a timedelta this is absolute? |
|
@jorisvandenbossche rereading the wiki page again today. I missed this section earlier
How do you read that? I'm going back and forth on it. I think that means we're OK, as python uses time deltas to represent the time between two points, and the spec allows
As one valid representation. I am concerned that other libraries don't implement an |
|
|
Not in the sense that it is defined on the wiki (or at least the possible notations for a duration). For example, "1 month" is not representable by a Timedelta in general. But anyway, this is probably too detailed discussion for this use case as long as we only specify days and below. |
|
@TomAugspurger my only remaining question is this in the JSON standard anywhere / common practice? (or is there anything for describing how to store durations / intervals)? For datetimes we have ISO and as epochs, is there such a thing for durations? (if so maybe we should have a kw arg |
|
|
ok @TomAugspurger then I think your |
|
merge on pass. |
jreback
closed this
in 6c11b91
Jan 20, 2017
|
thanks @TomAugspurger |
AnkurDedania
added a commit
to AnkurDedania/pandas
that referenced
this pull request
Mar 21, 2017
|
|
TomAugspurger + AnkurDedania |
1d5c4fb
|
TomAugspurger commentedJan 15, 2017
Split from #14904
A few questions before I finish all the docs / tests:
The spec seems very permissive about what's allowed, so we need to choose
(P0Y0M...)(no)P0DT...vs.PT...(yes)...T5HvsT05H(no)...6.000000000Svs.6S(yes)We probably want a reader for this format as well, maybe in the Timedelta constructor. Not sure if I'll have time to get to that before 0.20 . I'd rather prioritize the JSON table schema PR.