Add sequence_to_ctypes_array to convert a sequence to a ctypes array#3136
Merged
Add sequence_to_ctypes_array to convert a sequence to a ctypes array#3136
Conversation
7aa7d3a to
b0d3c3d
Compare
b0d3c3d to
7fe7ede
Compare
michaelgrund
approved these changes
Mar 23, 2024
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
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.
Description of proposed changes
The
kwargs_to_ctypes_arrayfunction 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
dimis not a keyword argument:This PR removes the old
kwargs_to_ctypes_arrayfunction and adds the newsequence_to_ctypes_arrayfunction. It's defined differently and should be called like:which I think is more readable.
The
Session.create_datamethod is also slightly refactored because thekwargsparameter 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.