-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data.copy
silently adding name
attribute
#1402
Comments
yes, the hash method is meant for comparisons but is a bit experimental and not very well tested. the addition of the name is indeed unintentional and can be easily fixed (will do). what is a bit more difficult to solve is the introduction of small numerical differences, due to subsequent operations like >>> vector = Vector(0.1, 0.2, 0.2)
>>> vector.unitized()
Vector(x=0.2672612419124244, y=0.5345224838248488, z=0.8017837257372731)
>>> Vector(*vector.unitized()).unitized()
Vector(x=0.26726124191242445, y=0.5345224838248489, z=0.8017837257372732)
>>> Vector(*Vector(*vector.unitized()).unitized()).unitized()
Vector(x=0.26726124191242445, y=0.5345224838248489, z=0.8017837257372732) the first time around, |
perhaps hashing needs to take some kind of tolerance into account... |
Cool. Thanks for the quick reply. So I guess I hold back at using hash for comparing geometry for now. I remember a while ago there was this concept of using geometric keys (some form of string representation and truncation) for comparison. And of course now comparison is much more robust using Tolerance class. I guess, comparison between geometry classes should still rely on the eq functions that can be customised. The thing about using hash as a comparison kind of implies that it is fast for me. I don't know enough. Perhaps hashing floats is just generally a bad idea. |
Describe the bug
I found that the Data.copy() mechanism somehow added the
name
attribute in thejson_string
after the copy. This affects native compass geometry classes (e.g. Frame) and also classes that I have inherited from data.The addition of this attribute only happens in the
to_jsonstring()
but not if I read the__data__
. However, it changes the result ofsha256()
and the copied object will return a differnt hash. (see example code below)Now, I'm not sure if this is the intended behavior (for version control?). My goal is to use a hash function to compare the data content of the objects. I assumed the
sha256()
would be for this purpose, but maybe it is not? If not, can you maybe clarify what is the best practice for comparing the data content between two objects, especially when the data contains geometry, str, and list of things.To Reproduce
The following example shows not only a problem related to the addition of
name
attribute, but also floating point difference during the copy of the frame. Both of which would throw off the hash comparison.output:
Expected behavior
I expect the
frame.sha256()
andframe.copy().sha256()
to return the same results.In general I want a copy mechanism that would actually return me the same object with the same data (I don't know what is the deal about the guid though, perhaps users can have a choice to copy the same guid too) . And that I want to be able to verify the result of that copy using some comparison function. I hope that these two functions would act like a pair, such that I can check my class implementation to make sure I did the
__data__
right.The text was updated successfully, but these errors were encountered: