great-tables icon indicating copy to clipboard operation
great-tables copied to clipboard

epic: Add the `fmt_duration()` method

Open rich-iannone opened this issue 1 year ago • 3 comments
trafficstars

The fmt_duration() method would be useful to have for transforming numerical values (and time duration values) to well-formatted and customizable duration strings.

rich-iannone avatar Feb 22 '24 16:02 rich-iannone

For me is the missing fmt_duration() almost showstopper as it literary breaks rendering any GT with duration column:

TypeError: '<' not supported between instances of 'datetime.timedelta' and 'int' error

The only workaround is to keep the duration columns as strings what is not very practical.

Looking forward to v0.11.0

vlcinsky avatar Jul 28 '24 21:07 vlcinsky

Hey @vlcinsky, thanks for flagging this error. Can you say a bit more about what triggers this error, or provide an example? I'm trying to reproduce. I noticed a different error when using a timedelta in polars, but wasn't able to reproduce the error message you received.

Here's what I tried

import polars as pl
import pandas as pd
from datetime import timedelta
from great_tables import GT

# polars ---
# error: casting from Duration(Microseconds) to String not supported
GT(pl.DataFrame({"some_duration": [timedelta(1)]}))

# pandas ---
# works okay
GT(pd.DataFrame({"some_duration": [timedelta(1)]}))

machow avatar Aug 16 '24 22:08 machow