-
Notifications
You must be signed in to change notification settings - Fork 472
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
copy.deepcopy(UnitRegistry()) #864
Conversation
copy.deepcopy misbehaves in case of dynamic class definition, such as that performed by >>> def gen_C():
... class C:
... pass
... return C
>>> C1 = gen_C()
>>> C2 = copy.deepcopy(C1)
>>> C2 is C1
True |
# Conflicts: # pint/testsuite/test_issues.py
...aaand done :) This gives some performance benefit compared to re-initialising everything from the beginning: %timeit pint.UnitRegistry()
135 ms ± 2.31 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
ureg = pint.UnitRegistry()
%timeit copy.deepcopy(ureg)
42.7 ms ± 799 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) |
@hgrecco this is ready for review and merge |
Great. I would like a second opinion as this is a rather large change. Maybe @andrewgsavage or @jondoesntgit can take also a look. |
@hgrecco @andrewgsavage @jondoesntgit ping - any observations before this can be merged? |
I don't have any observations. This is a bug that I've never had to worry about in my code. |
Me neither |
bors r+ |
Build succeeded |
Thank you! |
Closes #856
Allow creating an independent copy of a UnitRegistry through deepcopy().
Also introduce several speedups in UnitsContainer and ParserHelper.