Skip to content

Fix tuple reconstruction of non-mappable dataclasses - #469

Open
Linxiushen wants to merge 2 commits into
google-deepmind:mainfrom
Linxiushen:fix/non-mappable-tuple-conversion
Open

Linxiushen wants to merge 2 commits into
google-deepmind:mainfrom
Linxiushen:fix/non-mappable-tuple-conversion

Conversation

@Linxiushen

Copy link
Copy Markdown

from_tuple() passes a zip object as the sole positional constructor argument. This works for mapping dataclasses, but with mappable_dataclass=False a multi-field dataclass raises TypeError, and a one-field dataclass silently stores the zip object instead of its value.

Construct from field-name keyword arguments so both supported dataclass modes receive the original values. Extend the tuple round-trip test across mapping/non-mapping, mutable/frozen and keyword-only constructors, and check that a restored single JAX-array field still works in a jitted function.

Validation on Python 3.12 / JAX 0.11.2 CPU:

  • Unchanged source: 5 new cases fail, 4 mapping controls pass.
  • python -m pytest chex/_src/dataclass_test.py -q --tb=short: 69 passed.
  • The test.sh Flake8 selection and Google-configured Pylint on both changed files pass. Ruff reports the same two existing source diagnostics as the baseline, neither in changed code.

The full repository, docs, other Python versions and GPU tests were not run. This does not change pseudo-field or non-mapping init=False field behavior.

@google-cla

google-cla Bot commented Sep 27, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Linxiushen
Linxiushen force-pushed the fix/non-mappable-tuple-conversion branch from ef1ec96 to 63bfddb Compare September 28, 2026 03:54
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