-
Notifications
You must be signed in to change notification settings - Fork 188
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
: allow source
to be passed as a keyword argument
#5163
Data
: allow source
to be passed as a keyword argument
#5163
Conversation
f8d324a
to
5718650
Compare
Codecov Report
@@ Coverage Diff @@
## develop #5163 +/- ##
===========================================
- Coverage 80.93% 80.93% -0.00%
===========================================
Files 536 536
Lines 37056 37054 -2
===========================================
- Hits 29989 29985 -4
- Misses 7067 7069 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Hey, all good for me! Just have a quick question about the auto documentation of the code.
def __init__( | ||
self, | ||
ase=None, | ||
file=None, | ||
filename=None, | ||
values=None, | ||
source=None, | ||
scan_type=None, | ||
parse_policy=None, | ||
**kwargs | ||
): | ||
def __init__(self, ase=None, file=None, filename=None, values=None, scan_type=None, parse_policy=None, **kwargs): | ||
"""Construct a new instance and set the contents to that of the file. | ||
|
||
:param file: an absolute filepath or filelike object for CIF. | ||
Hint: Pass io.BytesIO(b"my string") to construct the SinglefileData directly from a string. | ||
:param filename: specify filename to use (defaults to name of provided file). | ||
:param ase: ASE Atoms object to construct the CifData instance from. | ||
:param values: PyCifRW CifFile object to construct the CifData instance from. | ||
:param source: |
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.
If I understand correctly the source
would be identified here as part of the kwargs
and passed down to super().__init__
, but since we are "overwriting" the __init__
wouldn't we loose the documentation aspect if we just remove this (this=the mention in the docstring and the explicit arg declaration)?
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.
Yes, we would lose it, but it shouldn't have been there in the first place. The fact that you can pass source
is also not in the docstring of any of all the other data plugins. This is something that should simply be documented in the documentation. Docstrings are not the place for this. This is a generic problem with any kind of subclassing system that allows to change signatures.
So I guess that is the real thing missing from this PR. I will look if I can add a section in the docs to document this feature.
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.
Docstrings are not the place for this.
Yeah, I'm still not super sure what docstrings are the place for really. With all the format limitations, the lack of support for expanding docstrings of parent classes instead of just overwriting, etc. I feel like they are quite limited and I am more and more hesitant to dedicate a lot of effort into them.
The `Data` class defines the `source` property which allows to get and set the `source` attribute. It was designed to hold information on the source of the data if it came directly from an external database. Prior to `aiida-core` v1.0 it was possible to set this attribute directly through the constructor as a keyword argument, but due to the refactoring of the ORM, this was no longer possible. It went undetected because it was never tested and the two data types where this feature is typically used, the `UpfData` and `CifData`, implemented the keyword argument themselves, hiding the fact that `Data` no longer supported it. The `Data` constructor signature is updated to once again recognize the `source` keyword argument, and the custom implementation is removed from the `UpfData` and `CifData` plugins which now simply rely on the super class. A section is added to the "How to work with Data" section in the docs to document this feature and to recommend its usage when constructing data nodes by hand from external databases.
5718650
to
fac5558
Compare
@ramirezfranciscof thanks for the review. I have added a section to the documentation explaining this feature |
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.
Great, thanks! Good to go
Fixes #5162
The
Data
class defines thesource
property which allows to get andset the
source
attribute. It was designed to hold information on thesource of the data if it came directly from an external database.
Prior to
aiida-core
v1.0 it was possible to set this attributedirectly through the constructor as a keyword argument, but due to the
refactoring of the ORM, this was no longer possible. It went undetected
because it was never tested and the two data types where this feature is
typically used, the
UpfData
andCifData
, implemented the keywordargument themselves, hiding the fact that
Data
no longer supported it.The
Data
constructor signature is update to once again recognize thesource
keyword argument, and the custom implementation is removed fromthe
UpfData
andCifData
plugins which now simply rely on the superclass.