Closed NickCrews closed 7 months ago
Thanks for the issue.
I think for the specific case of age and for any case where you need an integer number of some unit, give the delta
method a try.
Ideally your function could be:
def dob_to_age(dob: DateValue) -> FloatingValue:
"""Convert a date of birth to an age in years (float)."""
return ibis.now().delta(dob, "days") / 365.25
The other issues are somewhat orthogonal here:
IntervalValue
because of their fraught nature.delta
methoddelta
+ manual unit conversion is probably the only sane way right now to get what you want, especially because how you want to handle the ambiguities in unit definitions should be up to you as the user of ibis/your application/library.Let's discuss more about intervals in #8138. See https://github.com/ibis-project/ibis/issues/8138#issuecomment-1919702297 for details.
Is your feature request related to a problem?
I have this function
I had several annoying experiences implementing it
date.month()
. Interval uses a property. We should be consistent. I would vote for methods. Perhaps there are other places where there is this inconsistency we should consider when making this decision?unsupported operand type(s) for /: 'IntervalScalar' and 'float'
. I expect.days()
to give me anIntegerValue
, likeDate.month()
and friends.(ibis.now().date() - dob).years()
. But I get aCannot convert interval value from unit D to unit Y
with this. Which I think makes sense, because semantics to time are not strict and in some interpretations there aren't 365.25 days in a year. Not sure there is anything to do about this, but just wanted to flag this as something I'm running into. Not sure what backends do, but probably we are at their mercy and should just do what they do.Describe the solution you'd like
I think the best usage would be
(ibis.now().date() - dob).days() / 365.25
What version of ibis are you running?
main
What backend(s) are you using, if any?
No response
Code of Conduct