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 passing int for uint spec when int precision > uint precision #298

Merged
merged 3 commits into from
Feb 20, 2020

Conversation

rly
Copy link
Contributor

@rly rly commented Feb 19, 2020

Fix #294.

Previously, when the ObjectMapper receives an int64 value for a uint32 spec, HDMF would raise an error. An int64 for a uint64, however, worked. The error was only raised if the given int value's precision was higher than the spec uint's precision.

With this change:

  • if an int64/float64 value is given for a uint8/uint16/uint32/uint64 spec, the value will be converted to uint64
  • if an int32/float32 value is given for a uint8/uint16/uint32 spec, the value will be converted to uint32

A warning will also be raised when the given base type differs from the specified type, such that a conversion occurs, e.g., a float32 value is given for an int32 spec. This was previously converted invisibly.

@rly rly requested a review from ajtritt February 19, 2020 22:29
@codecov
Copy link

codecov bot commented Feb 19, 2020

Codecov Report

Merging #298 into dev will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #298      +/-   ##
==========================================
+ Coverage   72.59%   72.66%   +0.06%     
==========================================
  Files          33       33              
  Lines        6390     6395       +5     
  Branches     1396     1398       +2     
==========================================
+ Hits         4639     4647       +8     
+ Misses       1322     1319       -3     
  Partials      429      429
Impacted Files Coverage Δ
src/hdmf/build/objectmapper.py 65.89% <100%> (+0.68%) ⬆️

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 d432709...2676646. Read the comment docs.

@rly
Copy link
Contributor Author

rly commented Feb 19, 2020

@oruebel mentioned that an int64 cannot be held within a uint32. int64 supports -2^63 to 2^63-1. uint32 supports 0 to 2^32-1.

@oruebel also suggested that a warning be raised if HDMF converts the given value to a different base type.

The PR has been updated to reflect these changes.

@rly rly requested a review from oruebel February 19, 2020 23:47
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.

Some conversions fail
3 participants