Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: train_continuous() with integer64 #369

Closed
teunbrand opened this issue Nov 5, 2022 · 0 comments · Fixed by #374
Closed

Bug: train_continuous() with integer64 #369

teunbrand opened this issue Nov 5, 2022 · 0 comments · Fixed by #374

Comments

@teunbrand
Copy link
Contributor

Currently, train_continuous() gives nonsensical ranges for integer64 input.

library(scales)

new <- bit64::as.integer64(1:10)

train_continuous(new)
#> [1] 4.940656e-324 4.940656e-323

Looking at the the base::range.default function, it seems that concatenating NULL with an integer64 vector causes weird casting behaviour. This doesn't happen using the vctrs::vec_c() function for example.

existing <- NULL

c(existing, new)
#>  [1] 4.940656e-324 9.881313e-324 1.482197e-323 1.976263e-323 2.470328e-323
#>  [6] 2.964394e-323 3.458460e-323 3.952525e-323 4.446591e-323 4.940656e-323

vctrs::vec_c(existing, new)
#> integer64
#>  [1] 1  2  3  4  5  6  7  8  9  10

Created on 2022-11-05 by the reprex package (v2.0.1)

There are a few options to prevent this. In the following line

suppressWarnings(range(existing, new, na.rm = TRUE, finite = TRUE))

The input can be pre-combined:

suppressWarnings(range(vctrs::vec_c(existing, new), na.rm = TRUE, finite = TRUE))

The input can be coerced to numeric:

suppressWarnings(range(existing, as.numeric(new), na.rm = TRUE, finite = TRUE))

Or can be branched depending on the 'null'-ness of existing.

if (is.null(existing)) {
  suppressWarnings(range(new, na.rm = TRUE, finite = TRUE))
} else {
  suppressWarnings(range(existing, new, na.rm = TRUE, finite = TRUE))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant