Skip to content

All-NA list input to tfd() still collapses to length 0 (asymmetric with matrix path) #262

@fabian-s

Description

@fabian-s

Follow-up to #241. The matrix path correctly returns a length-n vector of NA-functions on all-NA input, but the list path still hits the "truly empty" branch in new_tfd() because tfd.list NA-strips entries to numeric(0) before calling new_tfd, and new_tfd sees zero non-empty entries and returns the prototype.

library(tf)
length(tfd(matrix(NA_real_, nrow = 3, ncol = 5), arg = 1:5))  # 3 — correct after #241
length(tfd(list(NA_real_, NA_real_), arg = list(c(1,2), c(1,2))))  # 0 — still buggy

Fix

tfd.list should not strip all-NA entries before passing to new_tfd; preserve a marker so new_tfd's all-NA branch is triggered with the original input size.

Regression test

test_that("all-NA list input preserves vec_size", {
  x <- tfd(list(NA_real_, NA_real_), arg = list(c(1, 2), c(1, 2))) |>
    suppressWarnings()
  expect_length(x, 2)
  expect_true(all(is.na(x)))
})

Found while reviewing PR for #241.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions