-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add type checks in constructors #210
Add type checks in constructors #210
Conversation
The type checks work but I am not sure if the implementation is clean enough (especially in the awkward constructors). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See below.
Thank you for such detailed explanations, @jpivarski! It took me some time to go through all the details, but they were extremely helpful! The code snippets were also very helpful! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The awkward
constructors now look much better! The numpy
type check still looks a bit messy as I encountered an edge case in the existing unit tests. Additionally, the type checks for numpy
vectors is currently happening in the __array_finalise__
method but would it be better to perform the check in the __new__
method?
Oh, the light package does not include |
Codecov Report
@@ Coverage Diff @@
## main #210 +/- ##
==========================================
+ Coverage 82.56% 82.63% +0.07%
==========================================
Files 96 96
Lines 10475 10524 +49
==========================================
+ Hits 8649 8697 +48
- Misses 1826 1827 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still a few instances of expensive data conversions for the sake of checking a data type.
Co-authored-by: Jim Pivarski <jpivarski@users.noreply.github.com>
Co-authored-by: Jim Pivarski <jpivarski@users.noreply.github.com>
Co-authored-by: Jim Pivarski <jpivarski@users.noreply.github.com>
…nsh/add-type-checks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review, @jpivarski! I have updated the PR with your suggestions! I have also updated the _is_type_safe
function in backends/numpy.py
to use the constructed vector. Now the function does not require converting a NumPy
vector to a list and then to a NumPy
array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does it! The type-checks are fully general (no missing cases that I can see) and only metadata are iterated over, so I don't see any potential performance issues.
I'd say go ahead and merge it.
Thank you for the constructive reviews! Merging this! |
See #205
Added type checks in all the existing constructors.