Better handling of timedelta
See original GitHub issueA minor issue: Timedelta aren’t correctly handled and formatted.
Using DatetimeTickFormatter
with e.g. '%jd %H:%M:%S'
to count the number of days/hours/minutes gives out 1d 00:00:00
(1 day) for t=0
when it should really be 0d 00:00:00
. It considers a datetime, hence January 1st of epoch, instead of a time range.
Using NumeralTickFormatter(format='00:00:00')
doesn’t work either as they’re automaticaly turned in float of ms in a data source, while this formatter uses seconds.
Using FuncTickFormatter
imposes installing flexx which breaks my conda environment (and is also not friendly).
Potential solution:
https://bokeh.pydata.org/en/latest/_modules/bokeh/util/serialization.html could be modified to set timedelta as seconds and document for the use of NumeralTickFormatter
in this specific case.
Workaround: turn timedelta dataframe columns to float with total_seconds()
before adding to the source then use NumeralTickFormatter
.
It seems that this issue is related to https://github.com/bokeh/bokeh/issues/5426
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
They are not converted to month/year representation. They are converted to absolute milliseconds (which is fine, the unit choice is arbitrary and ms has some advantages, see above).
They are are being displayed as datetimes because you have configured a datetime axis, which interprets all values a “ms since epoch” and displays them as datetimes accordingly. As stated above, it’s not sensical to use a datetime axis with timedeltas, because timedeltas are not datetimes. This is no different that if you added a datetime axis to a plot with
x_range=(0, 10)
. The result is probably not useful, but there’s no reason to expect it to be either. The answer is just: don’t use a datetime axis with timedeltas.It’s not clear to me that there is a single right or best format for timedeltas. Some users might want to expand out to +/- days/weeks/months. Other users might always want +/- seconds, regardless of scale. Given that any formatting anyone wants can now be achieved with
FuncTickFormatter
, it’s not a high priority to build in (and therefore have to maintain) more code about this. However if this is important enough to others to submit a PR, I’m happy to consider and review it.As what regards documentation, https://bokeh.pydata.org/en/0.13.0/docs/user_guide/plotting.html#datetime-axes contains the following statement (emphasis added by me)
Even if the numpy semantics of ‘datetime64’ and ‘timedelta64’ were clear to me, it was not obvious that ‘any data that involves dates or times’ excludes ‘timedelta64’. (And yes, I did not read the reference guide.)
However I agree that support of timedelta axes is not high priority, and may be it is better for the user to do scaling and formatting explicitly.