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

Fix missing value propagation in as_integers/doubles(), take 2 #319

Merged
merged 10 commits into from
May 25, 2023

Conversation

romainfrancois
Copy link
Collaborator

This reverts commit 3c87798.

@romainfrancois
Copy link
Collaborator Author

romainfrancois commented May 24, 2023

Turns out #265 is breaking something that I can't quite understand, see #318 for some drama. I'll try to approach its intent a different way.

(edit) it was a ci oversight 🤯

@romainfrancois romainfrancois mentioned this pull request May 25, 2023
@@ -85,6 +85,7 @@ jobs:
run: |
options(warn = 2)
pak::local_install_dev_deps("cpp11test", dependencies = TRUE)
install.packages(".", repos = NULL, type = "source")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @kevinushey @DavisVaughan just a FYI, because this has driven me insane over the past few days.

Because this is a non-standard setup that involves an extra package (cpp11test) that lives under the source tree, we actually do need to install cpp11 from locally, which is not done for usual testing (it just does R CMD build + check).

So I ended up testing against cran version instead of local, so:

  • none of the changes in header files were stressed, causing failures on ci.
  • but locally everything was fine

And then because I'm always more suspicious of my local setup than the ci, I tried a bunch of things (see #318 for some drama ci-based testing)

@@ -1,9 +1,7 @@
#include "Rversion.h"

#include "cpp11/doubles.hpp"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order of includes actually does not matter, make format can do its thing.

@@ -48,8 +49,17 @@ template <typename T>
inline T na();

template <typename T>
inline bool is_na(const T& value) {
inline typename std::enable_if<!std::is_same<typename std::decay<T>::type, double>::value,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I trust this approach more than an unconstrained template <typename T> followed by a fully specialized is_na<double>.

And also that means all of is_na() is in this one file.

doubles xn(x);
writable::integers ret = writable::integers(xn.size());
std::transform(xn.begin(), xn.end(), ret.begin(), [](double value) {
if (!is_convertible_without_loss_to_integer(value)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to consider the case when have (double)NA_INTEGER in a doubles, currently the static_cast<int> will turn this into NA_INTEGER so we end up with NA although we started with something that is not NA (in the double land).

Should is_convertible_without_loss_to_integer() return false in that case. R does this:

> as.integer(cpp11::cpp_eval("(double)NA_INTEGER"))
[1] NA
Warning message:
NAs introduced by coercion to integer range 

@romainfrancois romainfrancois changed the title Revert "Fix missing value propagation in as_integers/doubles() (#265)" Fix missing value propagation in as_integers/doubles(), take 2 May 25, 2023
@romainfrancois romainfrancois merged commit 28538e5 into main May 25, 2023
@romainfrancois romainfrancois deleted the revert_265 branch May 25, 2023 09:07
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 this pull request may close these issues.

1 participant