Skip to content

[BUG] NonTensorData.empty(names=...) ignores the names it is given #2501

Open

Description

@peterdsharpe

NonTensorData.empty() and MetaData.empty() accept names, but the result never gets them: it keeps the old names, or has none when a batch_size is also given without names. TensorDict.empty(names=...) sets the names, so code that passes names to empty() on any tensor collection gets the wrong names back when the collection is a non-tensor entry.

from tensordict import NonTensorData, TensorDict

print(NonTensorData("x", batch_size=[2]).empty(names=["n"]).names)
nt = NonTensorData("x", batch_size=[2], names=["m"])
print(nt.empty(names=["n"]).names, nt.empty(batch_size=[2], names=["n"]).names)
print(TensorDict(batch_size=[2]).empty(names=["n"]).names)
[None]
['m'] ['m']
['n']

Expected: ['n'] in every case, as TensorDict.empty(names=["n"]) gives.

Cause: NonTensorDataBase.empty (tensordict/tensorclass.py:5527-5536) sets names = None when a batch_size is given without names, and otherwise always replaces names with self._maybe_names(), so a names argument is never used.

Possible fix: use names when it is given, else None with a new batch_size, else self._maybe_names(). Only calls that pass names change, and those return the wrong names today. Found while working on #2467.

tensordict main (eba7879), torch 2.14.1, Python 3.12.12.

Activity

  1. added
    bugSomething isn't working
    triagedMaintainers have seen this issue and commented their findings.
    on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtensorclasstriagedMaintainers have seen this issue and commented their findings.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions