Skip to content
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

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Oct 5, 2021

Fixes #5162

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 update 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.

@codecov
Copy link

codecov bot commented Oct 5, 2021

Codecov Report

Merging #5163 (fac5558) into develop (5480267) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             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     
Flag Coverage Δ
django 75.78% <100.00%> (-<0.01%) ⬇️
sqlalchemy 74.93% <100.00%> (-<0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiida/orm/nodes/data/upf.py 79.57% <ø> (-0.34%) ⬇️
aiida/plugins/__init__.py 100.00% <ø> (ø)
aiida/orm/nodes/data/cif.py 86.81% <100.00%> (-0.06%) ⬇️
aiida/orm/nodes/data/data.py 61.66% <100.00%> (+0.42%) ⬆️
aiida/plugins/entry_point.py 93.75% <100.00%> (ø)
aiida/engine/daemon/client.py 75.26% <0.00%> (-1.01%) ⬇️
aiida/transports/plugins/local.py 81.66% <0.00%> (+0.26%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5480267...fac5558. Read the comment docs.

Copy link
Member

@ramirezfranciscof ramirezfranciscof left a 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.

Comment on lines -265 to -283
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:
Copy link
Member

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)?

Copy link
Contributor Author

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.

Copy link
Member

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.
@sphuber
Copy link
Contributor Author

sphuber commented Oct 6, 2021

@ramirezfranciscof thanks for the review. I have added a section to the documentation explaining this feature

Copy link
Member

@ramirezfranciscof ramirezfranciscof left a 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

@sphuber sphuber merged commit 83155d2 into aiidateam:develop Oct 6, 2021
@sphuber sphuber deleted the fix/5162/data-constructor-source-attribute branch November 8, 2021 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Source attribute can no longer be set through the Data constructor
2 participants