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 DataViews to become invalid fixes #502 #516

Merged
merged 19 commits into from
Aug 11, 2021

Conversation

jgrewe
Copy link
Member

@jgrewe jgrewe commented Jul 11, 2021

This PR changes the way ranges along a dimension are calculated.

  • allows DataView to be invalid and reading access will return an empty array

  • range calculation is delegated to the dimensions respecting the SliceMode.

  • allows for some simplification of the BaseTag._calc_data_slice method

  • We do not necessarily return at minimum a single value along a given dimension. If there are no data points between start and end position the range is invalid and the DataView will become invalid and return an empty array. Just like slicing a numpy array that does not return a result.

  • Invalid DataViews return no data extent, write access will raise an exception. They offer a "debug message" containing the reason of their invalidity.

  • I might be that I went a little far with removing the OOB and IncompatibleDimensions exceptions from DataView, happy to have your opinions..

@lgtm-com
Copy link

lgtm-com bot commented Jul 11, 2021

This pull request introduces 1 alert when merging 9a245a2 into f2c0cd6 - view on LGTM.com

new alerts:

  • 1 for Variable defined multiple times

@coveralls
Copy link

coveralls commented Jul 11, 2021

Coverage Status

Coverage increased (+0.05%) to 79.646% when pulling 430a6ee on jgrewe:invalid_slice into c5ffc3b on G-Node:master.

@codecov-commenter
Copy link

codecov-commenter commented Jul 11, 2021

Codecov Report

Merging #516 (dd2918c) into master (724c663) will increase coverage by 0.04%.
The diff coverage is 94.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #516      +/-   ##
==========================================
+ Coverage   81.25%   81.30%   +0.04%     
==========================================
  Files          81       81              
  Lines       10538    10730     +192     
==========================================
+ Hits         8563     8724     +161     
- Misses       1975     2006      +31     
Impacted Files Coverage Δ
nixio/exceptions/__init__.py 100.00% <ø> (ø)
nixio/multi_tag.py 79.41% <ø> (+0.42%) ⬆️
setup.py 0.00% <ø> (ø)
nixio/tag.py 76.95% <85.71%> (-9.14%) ⬇️
nixio/dimensions.py 91.04% <89.74%> (-0.29%) ⬇️
nixio/data_view.py 87.25% <93.54%> (+2.06%) ⬆️
nixio/data_array.py 91.66% <100.00%> (ø)
nixio/exceptions/exceptions.py 82.60% <100.00%> (+1.65%) ⬆️
nixio/test/test_data_view.py 100.00% <100.00%> (ø)
nixio/test/test_dimensions.py 99.59% <100.00%> (+0.07%) ⬆️
... and 2 more

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 b4ae900...dd2918c. Read the comment docs.

mpsonntag
mpsonntag previously approved these changes Aug 6, 2021
Copy link
Contributor

@mpsonntag mpsonntag left a comment

Choose a reason for hiding this comment

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

Looks good to me

"does not contain data.".format(slices)
)
else:
self._error_message = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Îf I read this line correctly this is the initialization of the self._error_message attribute. Why not move this line to before the if ... and remove the else clause. The first time I read it, I found it a bit confusing.

nixio/tag.py Outdated
else:
if dimunit is None and unit is not None:
raise IncompatibleDimensions(
"Units of position and SampledDimension "
Copy link
Contributor

Choose a reason for hiding this comment

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

Should "RangeDimension" also be considered at this point?

jgrewe added 19 commits August 11, 2021 22:57
no exceptions are thrown upon creation, DataView is invalid though and
reading the data will return an empty array
Adds a "debug_message" to troubleshoot why the DV might be empty
Adapts the tests
and returns the new position as well as the scaling factor, this
is done to separate scaling and getting the index for ranges/slices
where we need more control
the returned DataView will be invalid, though
Copy link
Contributor

@mpsonntag mpsonntag left a comment

Choose a reason for hiding this comment

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

Looks good to me now.

@mpsonntag mpsonntag merged commit b140b78 into G-Node:master Aug 11, 2021
@jgrewe jgrewe deleted the invalid_slice branch August 11, 2021 21:52
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.

4 participants