timechange icon indicating copy to clipboard operation
timechange copied to clipboard

Should `NaN` be treated as `NA`?

Open NicChr opened this issue 10 months ago • 0 comments

Hello, first of all thank you for the wonderful package!

I was wondering if the expected behaviour of adding units (e.g. days) with NaN values should match adding days with NA?

See the example below:

library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union

x <- dmy_hms("0101200 00:00:00", tz = "UTC")
#> Warning: All formats failed to parse. No formats found.

C_time_add <- get("C_time_add", asNamespace("timechange"))

C_time_add(x, list(day = NA), "preday", "NA")
#> [1] NA
C_time_add(x, list(day = NaN), "preday", "NA")
#> Error: All elements must be integer-like

Created on 2025-02-16 with reprex v2.1.1

This situation often arises in my testing code when I multiply Inf with 0 and I think it would be cleaner to not have to make a special case for this.

Thanks!

NicChr avatar Feb 16 '25 08:02 NicChr