Feature Request: Partial Date-Time objects #2051
Replies: 24 comments 3 replies
-
Thanks for the tag, @billdenney I think I haven't benchmarked the performance, but I was very conscious of trying to make it vectorized in all cases - it's held up to some pretty large datasets. Also, as you highlighted, it does not handle missing-in-the-middle scenarios (some quick tests below). For imputation alone, I think missing-in-the-middle would be a pretty minor update. But right now, anytime you do datetime arithmetic, any coarse uncertainty will cascade so missing-in-the-middle won't be preserved. The desired behavior in these cases isn't totally clear to me, though. Let me know what use cases you had in mind, I think it would be a fairly minimal change. A quick test, and with a very minor change to the parsing regex, the parser will accept missing-in-the-middle strings. This will be fine for parsing and imputation of missing-in-the-middle: > as.parttime("2022--13")
<partial_time<YMDhmsZ>[1]>
[1] "2022-NA-13"
> impute_time(as.parttime("2022--13"), "2022-07-13")
<partial_time<YMDhms+tz>[1]>
[1] "2022-07-13" But comparison operators don't always work: > as.parttime("2022--04") > as.parttime("2022-01-05")
[1] NA
> as.parttime("2022--04") > as.parttime("2022-01-03")
[1] TRUE
> as.parttime("2022--04") > as.parttime("2022-12-07")
[1] NA # this should be decidedly FALSE I'd have to review the spec, but I don't think these are valid ISO8601 datetimes anymore, so I would prefer to keep the default behavior as is and allow a |
Beta Was this translation helpful? Give feedback.
-
@dgkf Thanks! I had a typo in my example date. SDTM requires a dash ( I would not expect parttime to support the nonstandard CDISC format as its core method. Having a Does |
Beta Was this translation helpful? Give feedback.
-
Date typesDates are considered a subset of datetimes - just a datetime where the time components are missing. This has a bit of overhead because a matrix is still allocated which just contains Time typesTimes can be provided as well, but like the "missing-in-the-middle" case, the logic isn't really set up to handle situations where only a time is known. There was no intentional omission - the package just started off with a fairly specific use case in mind and this wasn't considered. I think it could be extended to cover these cases and repurpose a lot of the datetime logic to support times. If I were to go down that path, I think a standalone time should be treated as a timespan. That is, instead of interpreting "01:59pm" as "1:59pm" with a missing day, it generalizes more nicely to think of it as a duration of "13h 59s", which might have specific meaning if you know it is meant to represent a time on a day. This way it isn't a datetime with a missing date, but a duration with some amount of precision. Perhaps there could be different subclasses just for the sake of default formatting, but under the hood they'd be represented as timespans. |
Beta Was this translation helpful? Give feedback.
-
I'm thinking of dates and times a bit differently than date-times. The reason that I think of them differently is because the inherent missingness is different. Specifically, I'd rather not have the max of a date of "2022-07-13" be "2022-07-13T23:59:59" but for it to remain "2022-07-13". And, similarly, I'd want times to be handled in a way where the date-part is not considered missing but nonexistent. One way to possibly make them work within the current parttime having near-zero modification could be to have some fixed reference date without missingness for times (so internally, it would be represented like "0001-01-01Thh:mm:ss" for times, for instance). |
Beta Was this translation helpful? Give feedback.
-
I see - I think my preference would still be to try to wrangle this into the more general case. One mechanism might be to offer an imputation function that only imputes maximums to a specific resolution (in this case only to the "date") field, and make a specialized But I think we might be going off on a tangent here. I filed a separate issue dgkf/parttime#10 to think about this specific example. Feel free to open other issues/feature requests if there are other scenarios that might require a separate type. |
Beta Was this translation helpful? Give feedback.
-
That partial imputation would align well with the |
Beta Was this translation helpful? Give feedback.
-
For admiral we need a For both objects we need getters and setters for each component and a method which returns the object as ISO8601 character string. I think these are the minimum requirements for working on #1300. Helpful methods for the objects would be:
|
Beta Was this translation helpful? Give feedback.
-
Sharing summary of discussions over meeting:
Next steps:
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
@bundfussr, thanks for the list. It is helpful. I brought up invalid strings in dgkf/parttime#32, and I made an initial list of some invalid strings for testing in dgkf/parttime#31. Additional examples of valid and invalid strings for testing would help, if you think of them. |
Beta Was this translation helpful? Give feedback.
-
@billdenney just as FYI here's some cases that one of our admiral testers sent to us before that don't work in our current functions: |
Beta Was this translation helpful? Give feedback.
-
@rossfarrugia , I just made a PR for the test cases that you suggested (and some more variants) in dgkf/parttime#33. The first two are from the SDTMIG and were already in the first PR. |
Beta Was this translation helpful? Give feedback.
-
@bundfussr FYI {parttime} is now on CRAN https://cran.r-project.org/web/packages/parttime/index.html - please can you discuss at the core team meet Weds around whether this will be incorporated as an admiral dependency during this release or next? |
Beta Was this translation helpful? Give feedback.
-
@rossfarrugia , I have added it to the agenda. |
Beta Was this translation helpful? Give feedback.
-
@billdenney @dgkf we plan to bring the {parttime} dependency in from the release after this one - so during q1 next year as fyi |
Beta Was this translation helpful? Give feedback.
-
That sounds great! |
Beta Was this translation helpful? Give feedback.
-
@fshanlee Do you think you can still work on this for the Q1 release? |
Beta Was this translation helpful? Give feedback.
-
@zdz2101 , I don't think I will have time to work on this. Also, when I last looked at it, I think the {parttime} package implements a type of object as S4. I currently don't know enough about S4 objects and whether it would be simple to incorporate them into {admiral}. |
Beta Was this translation helpful? Give feedback.
-
@rossfarrugia @thomas-neitmann @bundfussr Shall we discuss this in our function review/rework meetings? I took off label for Q1-2023 release |
Beta Was this translation helpful? Give feedback.
-
@bms63 , I am not sure. I think we just need somebody who has time to implement it. Or do you questioning that we should use parttime in admiral? |
Beta Was this translation helpful? Give feedback.
-
@bms63 ok for me for this one to move to next release for June if we have too much on already. |
Beta Was this translation helpful? Give feedback.
-
Still think we should implement. |
Beta Was this translation helpful? Give feedback.
-
Closing this discussion as there hasn't been much appetite to implement. |
Beta Was this translation helpful? Give feedback.
-
necro-time!! @zdz2101 |
Beta Was this translation helpful? Give feedback.
-
The purpose of this issue is to discuss the needs of the partial date-time object from both a user perspective (where the users for the object would be focused on
admiral
developers-- notadmiral
users) and from a developer perspective (where the developers would be developers of the partial date-time object code).(This didn't seem to fit within the other issue templates. It's similar to a feature request, but it's a bit wider-ranging.)
This is related to #1300 (and a bit related to #1299). It is also related to tidyverse/lubridate#690 (see that issue for discussion of some of the challenges and suggestions on object formatting and needs).
@dgkf, I was just reminded about your
parttime
package which has a lot of overlap with this (https://github.com/dgkf/parttime). With a quick look, I think thatparttime
supports decreased precision but not missing-in-the-middle formats (for example, "2022--13" for missing month would not be supported). Is that correct? Might you be interested in collaborating on this?As discussed in the meeting a few minutes ago, there is a desire to have partial date-time objects that would be able to handle the ISO 8601 variant that is used across CDISC standards. The final location of the object may either be in
admiral
or in a new package. (CDISCpartialdate
? the package name would need consideration.)My initial thoughts on the object are:
lubridate::ymd_hm(x)
, the default maximum precision would be minutes.lubridate::ymd_hms(x, truncated=1)
, the default maximum precision would be seconds but they may be missing.My initial thoughts on the code are:
NA_integer_
; missing second would returnNA_real_
; missing timezone would returnNA_character_
. (Alternative: Should it returnNA_real_
for any part except timezone?)Additional thoughts?
Beta Was this translation helpful? Give feedback.
All reactions