question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better handling of timedelta

See original GitHub issue

A 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:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bryevdvcommented, Jun 24, 2018

clearly showing that timedelta64 should not be converted to month/year representation.

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.

0reactions
miccolicommented, Jun 25, 2018

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)

When dealing with timeseries data, or any data that involves dates or times, it is desirable to have an axis that can display labels that are appropriate to different date and time scales.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

10 timedelta (Python) Best Practices - CLIMB
Python's timedelta objects are great for handling date and time values, but there are a few best practices to keep in mind.
Read more >
5 Cold Knowledge Points About Python Timedelta
It is known that we can use days , hours , minutes , seconds and microseconds to define a time interval using timedelta....
Read more >
How to Use timedelta Objects in Python to Work with Dates
Create a basic timedelta object · Print the current date and time · Calculate a date in the future · Calculate a date...
Read more >
Python Timedelta [Complete Guide] - PYnative
Use the timedelta to add or subtract weeks, days, hours, minutes, seconds, microseconds, and milliseconds from a given date and time.
Read more >
Python | datetime.timedelta() function - GeeksforGeeks
Python timedelta() function is present under datetime library which is generally used for calculating differences in dates and also can be used ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found