Skip to content

Conversation

@jose-henriquezroa
Copy link
Contributor

No description provided.

@codecov
Copy link

codecov bot commented Jul 19, 2023

Codecov Report

Merging #1042 (640cbad) into master (ad65dd4) will increase coverage by 0.10%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1042      +/-   ##
==========================================
+ Coverage   88.39%   88.49%   +0.10%     
==========================================
  Files          78       78              
  Lines        8907     8915       +8     
==========================================
+ Hits         7873     7889      +16     
+ Misses       1034     1026       -8     

sub_tree.__to_dict(sub_dic)
dic[sub_tree_name] = sub_dic

def to_dict(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def to_dict(self):
@property
def dict(self):

You can make this a property
You could also define the __dict__ dunder method so that dict(your_object) works

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'd personally integrate __to_dict in the dict property, and then call directly the dict property in other parts of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PProfizi Will do! Wasn't aware of this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PProfizi Seems dict is meant for something else (e.g. object inspection).


def to_dict(self):
"""
Returns a dictionary representation of the DataTree
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you enforce the fact it is read-only if you return an actual Python dict?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was originally a comment from @cbellot000 meaning that modifying the attributes & attribute-names in the dict didn't actually modify anything the DataTree. Which on second thought, the fact that we return a dict makes it clear enough. But no harm in leaving there I think.

return coll_obj.get_integral_entries()

@property
def get_sub_tree_names(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def get_sub_tree_names(self):
def sub_tree_names(self):

return out

@property
def get_attribute_names(self):
Copy link
Contributor

@PProfizi PProfizi Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def get_attribute_names(self):
def attribute_names(self):

@jose-henriquezroa
We try not to make properties with "get" or "set" in their names as is it already explicit that this is a getter.

Copy link
Contributor

@PProfizi PProfizi Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also above, why not just call the methods to_json or from_txt without the read and write parts. This too seems explicit enough without it.

@PProfizi I missed this comment. I tried, the json written by the data-tree is not really conformant with the actual json format (might be a bug). It raises an error when casting it to a json object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point @PProfizi. In that I should implement an equivalent "attribute_name" with a setter decorator that raises an error when the users calls it, since the setter here shouldn't be implemented.
And yet I'm still not fully happy with this since it betrays a bit the expectation of the user. Because keeping the "get_" prefix makes it clear that its only a getter from the start.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jose-henriquezroa you do not have to implement the setter and make it raise an error if what you want is for people to not be able to set. Simply not specifying a setter is enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PProfizi You're right, my mistake. I misunderstood the "property".

Nonetheless, in the very particular case of the DataTree we've also defined the setattr function. Which means that if the user does data_tree.get_attribute_name = "hello", instead of throwing an error it's going to define an attribute in the data_tree object with key "get_attribute_name" and value "hello". So I guess using "properties" is too risky here still.

@jose-henriquezroa jose-henriquezroa marked this pull request as draft July 20, 2023 07:46
@jose-henriquezroa jose-henriquezroa marked this pull request as ready for review July 20, 2023 07:46
@jose-henriquezroa jose-henriquezroa marked this pull request as draft July 20, 2023 14:32
@jose-henriquezroa jose-henriquezroa marked this pull request as ready for review July 20, 2023 14:33
@PProfizi PProfizi changed the title add comment changes Update DataTree Jul 21, 2023
@jose-henriquezroa jose-henriquezroa merged commit 5b87a8a into master Jul 21, 2023
@jose-henriquezroa jose-henriquezroa deleted the refactor/data-tree-comments branch July 21, 2023 12:30
@PProfizi PProfizi added the enhancement New feature or request label Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants