BUG: Handle negative sign (-) when parsing ISO 8601 durations · Issue #37172 · pandas-dev/pandas (original) (raw)
Related to #37159, #29773, #36204, splitting out only dealing with the behavior of the negative sign when parsing ISO 8601 Durations.
The current behavior is somewhat counter intuitive:
"P-6DT0H50M3.010010012S"
parses as Timedelta( days=-6, minutes=50, seconds=3, milliseconds=10, microseconds=10, nanoseconds=12, )
, and the negative is only allowed right after the P descriptor. A negative in any other position will raise an error.
This comment notes that the original spec for 8601 doesn't mention negativity at all, but that some other "extensions" (e.g. usage of it in Java Duration) do support it. I have been unable to find the detailed ISO 8601 spec.
As far as I can tell, there are a few possibilities to deal with this here:
- explicitly drop support for the negative sign
- only support an overall "-" e.g.
"-P6DT1H" = Timedelta('-7 days +23:00:00')
and/or - support positive/negative on each, e.g.
"P7DT-1H3M" = Timedelta('6 days 23:03:00')
Originally posted by @mgmarino in #37159 (comment)