Skip to content

GH-38358: [R] NotImplemented: Function 'if_else' has no kernel matching input types (bool, bool, date32[day]) - #51292

Merged
thisisnic merged 2 commits into
apache:mainfrom
thisisnic:GH-38358-ifelse_boolbooldate
Sep 17, 2026
Merged

thisisnic merged 2 commits into
apache:mainfrom
thisisnic:GH-38358-ifelse_boolbooldate

Conversation

@thisisnic

@thisisnic thisisnic commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Rationale for this change

Error message which occurred for if_else() when an NA was incorrectly mapped to a logical one, not the right type

What changes are included in this PR?

cast NA to desired type

Are these changes tested?

Yep

Are there any user-facing changes?

Yep

@thisisnic
thisisnic requested a review from jonkeane as a code owner September 10, 2026 17:38
Copilot AI lite review requested due to automatic review settings September 10, 2026 17:38
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #38358 has been automatically assigned in GitHub to PR creator.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new cast_or_parse() null handling assumes x$is_valid exists (Scalar-only) and can error for Array inputs (used elsewhere), so the guard must be narrowed to Scalars.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes Arrow R dplyr::if_else() failures when a bare NA (logical null scalar) participates in type resolution against date/timestamp columns, by ensuring the NA is represented as a null scalar of the target Arrow type (GH-38358).

Changes:

  • Add a special-case in cast_or_parse() to avoid invalid scalar casts (e.g., bool -> date32) by producing a typed null instead.
  • Add a regression test covering if_else() with bare NA against Date and POSIXct columns.
File summaries
File Description
r/R/dplyr-funcs-simple.R Adjusts scalar casting logic so null scalars don’t attempt unsupported casts when aligning to a common type.
r/tests/testthat/test-dplyr-funcs-conditional.R Adds a test reproducing the if_else() bare-NA vs date/timestamp failure and validating the fix.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread r/R/dplyr-funcs-simple.R
Copilot AI review requested due to automatic review settings September 10, 2026 17:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The functional change is small, targeted, and covered by a regression test; the only feedback is a minor comment-clarity improvement.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

r/R/dplyr-funcs-simple.R:194

  • The comment here says we “skip the value cast and just create a null of the target type”, but the implementation actually creates a null scalar and then casts it. Rewording the comment would make the intent clearer (i.e., we avoid casting the invalid scalar’s inferred type such as bool -> date32).
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Comment on lines +894 to +895
date2 = if_else(date > as.Date("2014-01-01"), NA, date),
date3 = if_else(date > as.Date("2014-01-01"), date, NA),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

its the NAs here that are the issue?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, we're making sure they don't get converted to the default logical NAs instead of type-specific NAs

@jonkeane jonkeane left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One small question, but if I'm not totally confused about that, this is good to merge imo

@github-actions github-actions Bot added awaiting changes Awaiting changes awaiting merge Awaiting merge and removed awaiting committer review Awaiting committer review awaiting changes Awaiting changes labels Sep 16, 2026
@thisisnic
thisisnic merged commit 0abf0de into apache:main Sep 17, 2026
37 checks passed
@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting merge Awaiting merge labels Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants