feat: Implement flexible ArrayLike input handling for arrays, lists, and tuples#73
Open
Spkap wants to merge 2 commits intoOSIPI:mainfrom
Open
feat: Implement flexible ArrayLike input handling for arrays, lists, and tuples#73Spkap wants to merge 2 commits intoOSIPI:mainfrom
Spkap wants to merge 2 commits intoOSIPI:mainfrom
Conversation
Implements the suggestion from PR OSIPI#63 to improve input flexibility using `numpy.typing.ArrayLike`. Allows lists and tuples as inputs alongside NumPy arrays. - Replaced `NDArray` hints with `ArrayLike` for array parameters. - Added internal `np.asarray()` for conversion. - Maintained float dtype checks post-conversion. - Scalar parameters (`np.floating`) remain unchanged. - Added new tests (`test_array_like_inputs.py`) covering list/tuple inputs, float dtypes, and error handling.
Contributor
Author
|
Hi @ltorres6, Following up on our discussion in PR #63, I've created a separate PR to implement ArrayLike support for more flexible array inputs (lists, tuples). I have also ran tests locally with pytest. Could you please review it when you have a chance? I will address any feedback and make any necessary changes. Thanks you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR enhances the flexibility and usability of osipi functions by implementing support for array-like inputs. Users can now pass Python lists and tuples, in addition to np.ndarrays, for parameters representing array data.
Background:
During the review of PR #63 (which focused on fixing initial type annotations using
NDArray), @plaresmedima and @ltorres6 suggested improving usability by accepting more general array-like types (like lists and tuples), aligning better with standard NumPy practice. This PR fulfills that follow-up action.How it Works:
For Array-Like Inputs (
t,ca,R1,S, etc.):NDArraytonumpy.typing.ArrayLike.np.asarray()on these inputs upon entry. This converts lists, tuples, or existing arrays into NumPy ndarrays..astype(np.float64)).For Scalar Inputs (
k,TR,a,Ktrans,ve,r1, etc.):np.floatingtype hints.np.asarray()is not called on scalars. They are used directly.Consistency Achieved:
ArrayLike+np.asarray) for all parameters designed to accept array data.Testing:
tests/test_array_like_inputs.py) has been added to verify:np.ndarray,list, andtupleinputs.float32andfloat64dtypes.TypeErrororValueErroris raised for invalid inputs (e.g., strings, incorrect dimensions).pytestand passed successfully before submission.