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

Allow supplying np_arrays or list for multi_tags positions #436

Merged
merged 7 commits into from
Mar 13, 2020

Conversation

hkchekc
Copy link
Member

@hkchekc hkchekc commented Mar 6, 2020

Also for extents.

Referring to #418, #789.

Also add some test for this constructor.

@lgtm-com
Copy link

lgtm-com bot commented Mar 6, 2020

This pull request introduces 1 alert when merging 41ceed4 into 5275a39 - view on LGTM.com

new alerts:

  • 1 for Unused import

@btel
Copy link
Member

btel commented Mar 6, 2020

Codecov Report

Merging #436 into master will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #436      +/-   ##
==========================================
+ Coverage   90.41%   90.46%   +0.04%     
==========================================
  Files          55       55              
  Lines        7087     7118      +31     
==========================================
+ Hits         6408     6439      +31     
  Misses        679      679              
Impacted Files Coverage Δ
nixio/block.py 65.16% <ø> (+0.11%) ⬆️
nixio/multi_tag.py 82.32% <100.00%> (+1.48%) ⬆️
nixio/test/test_multi_tag.py 100.00% <100.00%> (ø)
nixio/hdf5/h5group.py 80.86% <0.00%> (-0.39%) ⬇️
nixio/section.py 80.97% <0.00%> (+0.07%) ⬆️
nixio/property.py 71.74% <0.00%> (+0.25%) ⬆️

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 b19e5ad...4bc46e7. Read the comment docs.

nixio/multi_tag.py Outdated Show resolved Hide resolved
nixio/multi_tag.py Outdated Show resolved Hide resolved
nixio/multi_tag.py Outdated Show resolved Hide resolved
nixio/test/test_multi_tag.py Show resolved Hide resolved
@lgtm-com
Copy link

lgtm-com bot commented Mar 9, 2020

This pull request introduces 1 alert when merging 3d8d938 into e1d56ec - view on LGTM.com

new alerts:

  • 1 for Unused import

if name in blk.data_arrays:
del blk.data_arrays[name]
pos = blk.create_data_array(name, "{}-positions".format(self.type),
data=da)
Copy link
Member

Choose a reason for hiding this comment

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

What if da is an integer or string or some other invalid value? I think it would be confusing for the user if they were trying to create a MultiTag and they got an error about DataArray creation with invalid data. We should catch this issue as early as possible, preferably in the create_multi_tag() method in the Block class.

Also, I think this might not be the best location for the convenience functionality to be in general. Having it here makes it possible to create DataArrays by assigning values to mtag.positions. While this might sound useful, it also makes it more likely that a user tries to do something like:

mtag.positions = [10, 11]
# ... later
mtag.positions = [10, 11, 12]
# or
mtag.positions += [13]

which will lead to all sorts of errors: Duplicate names for the DataArray creation, attempting to append a list to a DataArray, etc.

I think the convenience should only be in the block.create_multi_tag() method and nowhere else, and it should be documented clearly in the arguments in the docstring. The type check for the positions argument in create_multi_tag should check for DataArray or any kind of sequence.

Comment on lines 85 to 94
ext = da
if not isinstance(da, DataArray):
blk = self._parent
name = "{}-extents".format(self.name)
if name in blk.data_arrays:
del blk.data_arrays[name]
ext = blk.create_data_array(name,
"{}-extents".format(self.type)
, data=da)
self._h5group.create_link(ext, "extents")
Copy link
Member

Choose a reason for hiding this comment

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

Given my comments above about not having the convenience functionality in the positions setter, I think the same should apply to extents.
I'm thinking we could have an extents argument in the create_multi_tag() method that works the same way as positions.

In both cases (for positions and extents), I think it only really makes sense to allow the user to automatically create DataArrays for MultiTag positons and extents once per MultiTag, on creation. Otherwise, we're creating an incentive for users to create, recreate, and change the positions and extents through these creation functions and that would lead to losing track of DataArray creation, causing naming conflicts and other issues.

nixio/block.py Outdated
Comment on lines 91 to 92
positions = self.create_data_array(da_name, "{}-positions".format(type_),
data=positions)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
positions = self.create_data_array(da_name, "{}-positions".format(type_),
data=positions)
positions = self.create_data_array(da_name, "{}-positions".format(type_),
data=positions)

nixio/block.py Outdated
mtag = MultiTag._create_new(self, multi_tags, name, type_, positions)
if not isinstance(positions, DataArray):
da_name = "{}-positions".format(name)
positions = self.create_data_array(da_name, "{}-positions".format(type_),
Copy link
Member

Choose a reason for hiding this comment

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

Might be good to catch any DA creation exceptions here, specifically any exception that will be thrown if the positions data is invalid. We could then re-raise it from here with a more appropriate message that mentions the MultiTag positions array explicitly.

nixio/block.py Outdated
Comment on lines 95 to 97
extents = self.create_data_array(da_name,
"{}-extents".format(type_)
, data=extents)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
extents = self.create_data_array(da_name,
"{}-extents".format(type_)
, data=extents)
extents = self.create_data_array(da_name,
"{}-extents".format(type_),
data=extents)

See also above comment about the DataArray creation exceptions.

nixio/block.py Outdated
extents = self.create_data_array(da_name,
"{}-extents".format(type_)
, data=extents)
mtag = MultiTag._create_new(self, multi_tags, name, type_, positions, extents)
Copy link
Member

Choose a reason for hiding this comment

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

Don't change the MultiTag._create_new() method. Just add extents to the mtag after it's created.

@lgtm-com
Copy link

lgtm-com bot commented Mar 12, 2020

This pull request fixes 1 alert when merging 61fdde0 into ff5c813 - view on LGTM.com

fixed alerts:

  • 1 for Unused exception object

Copy link
Member

@achilleas-k achilleas-k left a comment

Choose a reason for hiding this comment

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

Error handling changes discussed.

@lgtm-com
Copy link

lgtm-com bot commented Mar 12, 2020

This pull request fixes 1 alert when merging 43019f0 into ff5c813 - view on LGTM.com

fixed alerts:

  • 1 for Unused exception object

achilleas-k
achilleas-k previously approved these changes Mar 13, 2020
@achilleas-k
Copy link
Member

Looks good. I'd like to see some more extensive tests. Like having invalid positions (not just None, but like a single value), valid positions but invalid extents (and check if the positions DA was deleted when the exception is caught) etc.

Let me know if you want to include them here. Otherwise rebase and I'll merge.

@hkchekc
Copy link
Member Author

hkchekc commented Mar 13, 2020

Ok, then don't merge now. I will include them here

@lgtm-com
Copy link

lgtm-com bot commented Mar 13, 2020

This pull request fixes 1 alert when merging 63787ad into 6d0b2f3 - view on LGTM.com

fixed alerts:

  • 1 for Unused exception object

@lgtm-com
Copy link

lgtm-com bot commented Mar 13, 2020

This pull request fixes 1 alert when merging a250bd6 into 6d0b2f3 - view on LGTM.com

fixed alerts:

  • 1 for Unused exception object

@achilleas-k achilleas-k merged commit 38a96ab into G-Node:master Mar 13, 2020
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.

3 participants