Repository navigation
Include string_type in StringArray equality - #27
Open
1AbdullahButt wants to merge 1 commit into
Open
1AbdullahButt wants to merge 1 commit into
1AbdullahButt wants to merge 1 commit into
Conversation
StringArray inherited Array.__eq__, which only compares shape and dtype. Every StringArray has dtype object, so a str spec and a bytes spec compared equal even though they accept different values. Compare string_type too, the same way BoundedArray extends equality with its bounds. Fixes google-deepmind#26.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #26.
Cause.
StringArrayinheritedArray.__eq__, which only comparesshapeanddtype. EveryStringArrayhasdtype=object, soStringArray((2,), string_type=str)and the same spec withstring_type=bytescompared equal, even though each rejects the other's values invalidate.Fix.
StringArray.__eq__now also comparesstring_type, in the same wayBoundedArray.__eq__adds its bounds on top of the base comparison. Names are still ignored, as for the other specs. Defining__eq__keeps the class unhashable, as before.Tests. New tests in
StringArrayTest: equal specs with different names (scalar, 1-D, 2-D), str vs bytes compare unequal both ways (scalar, 1-D, 2-D, made withreplace), different shapes are unequal, and the spec is still unhashable.What I ran (Python 3 venv with absl-py, numpy, dm-tree, pytest):
python -m pytest -q dm_env/specs_test.py: 109 passed.specs.pychange reverted,python -m pytest -q dm_env/specs_test.py -k StringArray: the 3testNotEqualDifferentStringTypecases fail, the rest pass.AI disclosure: this change was written with Claude Code (an AI coding assistant) and reviewed before submitting.
🤖 Generated with Claude Code