Skip to content

apply_to_collections raises for defaultdict inputs #529

Open

Description

@ktz03

🐛 Bug

apply_to_collections raises TypeError: first argument must be callable or None when the first collection is a standard-library defaultdict, even when both inputs have identical keys. The corresponding plain-dictionary operation succeeds.

To Reproduce

from collections import defaultdict
from operator import add
from lightning_utilities.core.apply_func import apply_to_collections

left = defaultdict(int, count=2)
right = defaultdict(int, count=3)
result = apply_to_collections(left, right, int, add)

This fails with TypeError: first argument must be callable or None. Using None or list as the factory also fails.

Expected behavior

Return a defaultdict containing {"count": 5} and preserve the first input's default_factory, as the single-collection helper already does.

Additional context

Reproduced from current main 9a53be868a1cda6349f5daf5112e80c6143635f6 on Windows with Python 3.12.14. This reproducer uses only standard-library values; PyTorch and CUDA are not required.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions