-
Notifications
You must be signed in to change notification settings - Fork 192
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
👌 IMPROVE: constructor of base data types #5165
👌 IMPROVE: constructor of base data types #5165
Conversation
11b421e
to
82fc7aa
Compare
Seems there were already some tests for I also noticed that these tests use test classes based on |
yep |
82fc7aa
to
eb830de
Compare
Alright, refactored the basetype tests. I also moved the Some things I found out while working on this:
In [1]: 'a' + 'b'
Out[1]: 'ab'
In [2]: True + False
Out[2]: 1 Doing this for
In [3]: abs(Float(-2.0))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-324814f1c59f> in <module>
----> 1 abs(Float(-2.0))
TypeError: bad operand type for abs(): 'Float'
In [4]: f = Float(2)
In [4]: f += 2.0
In [5]: f
Out[5]: <Float: uuid: 8ee7db38-6a28-442f-8bfb-827de8f9d897 (unstored) value: 4.0>
In [6]: f.store()
Out[6]: <Float: uuid: 8ee7db38-6a28-442f-8bfb-827de8f9d897 (pk: 1) value: 4.0>
In [7]: f += 0.1
In [8]: f
Out[8]: <Float: uuid: cbf4b5ee-1474-46d6-aa48-c11a0639d12f (unstored) value: 4.1> |
Codecov Report
@@ Coverage Diff @@
## develop #5165 +/- ##
===========================================
+ Coverage 81.31% 81.31% +0.01%
===========================================
Files 529 529
Lines 37031 37031
===========================================
+ Hits 30107 30108 +1
+ Misses 6924 6923 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
4b32d62
to
499c4fe
Compare
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.
Thanks, @mbercx! Looks good to me.
As for the tests files move to node/data/
, I like this new folder refactoring, it has more parallel structure with the code they test.
def __init__(self, value=None, **kwargs): | ||
"""Initialise a ``Dict`` node instance. |
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.
Just want to make sure this will not break any backwards compatibility, correct? We can still use d = orm.Dict(dict={})
.
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.
Okay, I see a test case for this particular. 👍
Adapt the constructor of the `Dict` and `List` data types so the value no longer needs to be provided as a keyword argument, but can simply be passed as the first input. Remove the `*args` from the `BaseType` constructor, instead specifying the `value` input argument. Otherwise users could just pass multiple positional arguments and it would only use the first without raising an error. Also fixes two issues with the `List` class: * The `remove` method was not working as prescribed. Instead of removing the first element in the list with the specified value, it simply deleted the element with index `value`. * The `set_list()` method didn't make a copy of the `list` input, so any modification done to the `List` instance would also affect the original `list`. If the same list is used to initialise several `List` instances, adapting one would affect the other. Finally, add tests for the `List` class.
499c4fe
to
63e590d
Compare
Thanks for the review @unkcpz! Just rebased, good to merge once the test complete. |
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.
Thanks @mbercx!
We recently adapted the constructors of the `Dict` and `List` nodes so they no longer require the `dict` and `list` keywords, see: aiidateam/aiida-core#5165 Here we add a transformer that automatically removes these keywords from `Dict` and `List` constructors if present.
We recently adapted the constructors of the `Dict` and `List` nodes so they no longer require the `dict` and `list` keywords, see: aiidateam/aiida-core#5165 Here we add a transformer that automatically removes these keywords from `Dict` and `List` constructors if present.
We recently adapted the constructors of the `Dict` and `List` nodes so they no longer require the `dict` and `list` keywords, see: aiidateam/aiida-core#5165 Here we add a transformer that automatically removes these keywords from `Dict` and `List` constructors if present.
We recently adapted the constructors of the `Dict` and `List` nodes so they no longer require the `dict` and `list` keywords, see: aiidateam/aiida-core#5165 Here we add a transformer that automatically removes these keywords from `Dict` and `List` constructors if present.
We recently adapted the constructors of the `Dict` and `List` nodes so they no longer require the `dict` and `list` keywords, see: aiidateam/aiida-core#5165 Here we add a transformer that automatically removes these keywords from `Dict` and `List` constructors if present.
Adapt the constructor of the
Dict
andList
data types so thevalue no longer needs to be provided as a keyword argument, but can
simply be passed as the first positional argument.
Remove the
*args
from theBaseType
constructor, instead specifyingthe
value
input argument. Otherwise users could just pass multiplepositional arguments and it would only use the first without raising an
error.
Also fixes two issues with the
List
class:remove
method was not working as prescribed. Instead ofremoving the first element in the list with the specified value, it
simply deleted the element with index
value
.set_list()
method didn't make a copy of thelist
input, so anymodification done to the
List
instance would also affect the originallist
. If the same list is used to initialise severalList
instances,adapting one would affect the other.
Finally, add tests for the
List
class.