-
Notifications
You must be signed in to change notification settings - Fork 2
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 Continuous Integration #25
Conversation
1204be0
to
f03b3ee
Compare
3451a35
to
aa315fc
Compare
@LiamPattinson I've spent a while getting this to conform to mypy, but this is the first time I've really used it this extensively in a project or with numpy, and there were a few difficult bits. Would you be willing to do a code review on this PR at all once I feel it's ready to go? |
Can do, but I'm super-busy with work at the minute, so might not be able to look at it in detail for a little while. Feel free to ping me for any specific issues though. One thing I noticed at a glance is that pylint seems to be flagging up a lot of errors that are actually pretty reasonable stylistic choices. It might be worth disabling a bunch of the linting rules project-wide, or maybe switching out for something a bit more permissive like flake8. |
Thanks @LiamPattinson and completely understandable. Yeah - I've disabled the pylint checks for the time being whilst I develop but will add exceptions to specific lines where I feel I am correct. The bit I most want reviewed is the mypy stuff.
had to become
to satisfy mypy that it would never return an array. However, this feels very verbose. Also I spent ages trying to get numpy to play nice. Eventually settled on using |
Would If its code which should work either on numpy arrays or built-in floats, I find the best solution is to convert to 0D arrays as standard: # ArrayLike will catch scalars, np.ndarray, lists, tuples, etc
def myfunc(scalar_or_array: np.typing.ArrayLike) -> np.ndarray:
# Ensure the input is converted to nd.array
# If passed a scalar, it becomes a weird 0D array, but due to duck typing this
# rarely matters in practice and it behaves just like a built-in scalar type.
# Other options:
# - np.asanyarray: converts to ndarray, but won't copy data if given an array view or something
# - np.asfarray: shorthand for np.asarray(myarray, dtype=float)
scalar_or_array = np.asarray(scalar_or_array)
... do the rest of the function ... I don't actually use mypy or any other static type checker in my own work, and use type hints more as in-code documentation, so I can't say whether that'd be enough to keep mypy happy. |
Sorry if this is stuff you already know, but the numpy typing docs have some stuff on mypy and some general advice for keeping type checkers happy. It says there that any functions that can return either scalars or arrays are currently typed as simply returning |
Yes, though to be honest I found the numpy typing docs fairly opaque... 😅 On the topic of forcing float with Seem to be making progress though... |
Thanks to comments from @LiamPattinson in #26 I have made some changes to remove mypy from the testing process to run only on linting. Commits are a bit small and messy but... eehhhh All 'legitimate' linting errors have been addressed. |
I'm going to merge this now as the base aim of adding CI has been met. The fact that pylint is not passing hints at some of the code smelling a bit dodgy and requiring a refactor. This should be fixed when addressing some other issues (e.g. #24 ). To encapsulate all of this I'll open a new issue for getting CI green. |
Yeah, I think that's a sensible way of going about it. Better to clean up the code piece-by-piece as you're doing general refactoring than to spend hours polishing something you're just going to rewrite in a few weeks anyway. |
Add continuous integration:
Separate yaml files for linting and testing.
Will close #20