Add sequence_to_ctypes_array to convert a sequence to a ctypes array #3136
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.
Description of proposed changes
The
kwargs_to_ctypes_array
function was one of the oldest functions in PyGMT. It was first added in PR #55 (It's 2017! Seven years ago!) and has not changed since then.The function converts a sequence (like a list or a tuple) into a ctypes array, but the sequence must be the argument of a keyword dictionary, so it's called like this:
but why not just have a more general function
sequence_to_ctypes_array
, which can be called like:The new function also works if
dim
is not a keyword argument:This PR removes the old
kwargs_to_ctypes_array
function and adds the newsequence_to_ctypes_array
function. It's defined differently and should be called like:which I think is more readable.
The
Session.create_data
method is also slightly refactored because thekwargs
parameter makes little sense in this method.PR #3137 adds a similar function that converts a sequence of strings into a ctypes array. Better to review these two PRs back-to-back.