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

Change dtype conversion warning to include path to type #311

Merged
merged 10 commits into from
Apr 1, 2020

Conversation

rly
Copy link
Contributor

@rly rly commented Mar 12, 2020

Fix #306.

Note that this gives the path to the spec value, NOT the container hierarchy. It might not be as intuitive to users as giving the container hierarchy; however, that would require a large amount of refactoring, given how certain functions are currently encapsulated.

@codecov
Copy link

codecov bot commented Mar 18, 2020

Codecov Report

Merging #311 into dev will increase coverage by 0.06%.
The diff coverage is 97.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #311      +/-   ##
==========================================
+ Coverage   72.76%   72.83%   +0.06%     
==========================================
  Files          33       33              
  Lines        6443     6452       +9     
  Branches     1410     1411       +1     
==========================================
+ Hits         4688     4699      +11     
+ Misses       1327     1326       -1     
+ Partials      428      427       -1     
Impacted Files Coverage Δ
src/hdmf/build/objectmapper.py 66.61% <94.44%> (+0.18%) ⬆️
src/hdmf/build/warnings.py 100.00% <100.00%> (ø)
src/hdmf/spec/spec.py 72.51% <100.00%> (+0.45%) ⬆️
src/hdmf/validate/validator.py 71.05% <100.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 5492dfa...8d293ea. Read the comment docs.

oruebel
oruebel previously approved these changes Mar 18, 2020
@oruebel
Copy link
Contributor

oruebel commented Mar 18, 2020

I think having the spec path should be helpful enough. At least for developers it should make the debugging easier.

spec_path = self.name
spec = self.parent
while spec is not None:
spec_path = spec.name + '/' + spec_path
Copy link
Contributor

Choose a reason for hiding this comment

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

I couple things...

  • Not all specs have name set, so in the case of data_type specs (e.g. DynamicTable), this will be ambiguous. You might consider having the BaseStorageSpec constructor pass in data_type_def as name.
  • Since parent can't be reassigned, shouldn't this value be constant i.e. it shouldn't need to be computed every time the function gets called?
  • I think this should be a property. Is there a reason you didn't go that route?
  • I prefer path to path_str. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Not all specs have name set, so in the case of data_type specs (e.g. DynamicTable), this will be ambiguous. You might consider having the BaseStorageSpec constructor pass in data_type_def as name.

Gotcha. It turns out there is already in Validator.get_spec_loc that does what Spec.path_str was trying to do, but takes into account cases with a data_type_def or data_type_inc and no name. So I moved that code into Spec and refactored Validator.get_spec_loc(cls, spec) to call it.

  • Since parent can't be reassigned, shouldn't this value be constant i.e. it shouldn't need to be computed every time the function gets called?

Parent can be assigned after the spec is created. It's an odd case, but you can create a GroupSpec A with a path 'A'. Spec A could be added to GroupSpec B and would then have path 'B/A'. Spec B could be added to GroupSpec C and would then have path 'C/B/A', and so on.

  • I think this should be a property. Is there a reason you didn't go that route?

No reason. It does make sense as a property (getter only). I changed it. However, if it is not a constant, should it still be a property?

  • I prefer path to path_str. What do you think?

Agreed. I like path better. I changed it.

tests/unit/spec_tests/test_group_spec.py Show resolved Hide resolved
@rly rly requested a review from ajtritt March 26, 2020 01:32
@@ -361,6 +375,24 @@ def resolve_spec(self, **kwargs):
for attribute in inc_spec.attributes:
self.__new_attributes.discard(attribute)
if attribute.name in self.__attributes:
# copy over the fields 'shape' and 'dims' of the parent attribute to this spec's attribute
Copy link
Contributor

Choose a reason for hiding this comment

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

This modification happened in #321

@@ -680,6 +712,30 @@ def __is_sub_dtype(cls, orig, new):
@docval({'name': 'inc_spec', 'type': 'DatasetSpec', 'doc': 'the data type this specification represents'})
def resolve_spec(self, **kwargs):
inc_spec = getargs('inc_spec', kwargs)
# copy over fields of the parent dataset to this spec
Copy link
Contributor

Choose a reason for hiding this comment

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

This modification happened in #321

@rly rly merged commit 2530a3b into dev Apr 1, 2020
@rly rly deleted the enh/convert_dtype_warn branch April 1, 2020 22:49
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.

Include object name in UserWarning "Value with data type x is being converted to y"
3 participants