-
Notifications
You must be signed in to change notification settings - Fork 89
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
fix: pass memo to deepcopy #1698
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right—I can't think of a legitimate case in which an ak.Array instance is inside of the behavior
dict, but this is formally correct and if such a situation does show up in the future, this implementation fixes a potential bug.
I'm setting up auto-merge.
Codecov Report
Additional details and impacted files
|
NB - this PR is now placing more importance on |
Presumably, if someone actually says my_new_array = copy.deepcopy(my_awk_array) then they don't want But, behaviors contain class objects and functions. We don't want them to be copied. >>> import copy
>>> def some_function(x): return x
...
>>> class SomeClass: pass
...
>>> behavior = {"function": some_function, "class": SomeClass, some_function: "as key"}
>>> copied_behavior = copy.deepcopy(behavior)
>>> behavior["function"] is copied_behavior["function"]
True
>>> behavior["class"] is copied_behavior["class"]
True
>>> list(behavior.keys())[2]
<function some_function at 0x1057c7e20>
>>> list(behavior.keys())[2] is list(copied_behavior.keys())[2]
True Okay: they're not. |
Yes, right now this would only be an issue if a user is passing an instance method (or other non-atomically copied value) into class SpecialAdder:
def add(self, x, y):
...
ak.behavior[np.add, "point", "point"] = SpecialAdder().add Whilst I don't anticipate this, I think it's worth discussing it up-front in case we this these kinds of issues later. |
@jpivarski whoops, somehow I missed this on your PR.