GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add sequence_to_ctypes_array to convert a sequence to a ctypes array by seisman · Pull Request #3136 · GenericMappingTools/pygmt

Conversation

@seisman

@seisman seisman commented Mar 23, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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:

dim = kwargs_to_ctypes_array("dim", kwargs, ctp.c_uint64 * 4)

but why not just have a more general function sequence_to_ctypes_array, which can be called like:

dim = sequence_to_ctypes_array(kwargs.get("dim"), ctp.c_uint64 * 4)

The new function also works if dim is not a keyword argument:

dim = sequence_to_ctypes_array(dim, ctp.c_uint64 * 4)

This PR removes the old kwargs_to_ctypes_array function and adds the new sequence_to_ctypes_array function. It's defined differently and should be called like:

dim = sequence_to_ctypes_array(dim, ctp.c_uint64, 4) 

which I think is more readable.

The Session.create_data method is also slightly refactored because the kwargs 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@seisman
seisman force-pushed the sequence_to_ctypes_array branch from 7aa7d3a to b0d3c3d Compare March 23, 2024 07:53
@seisman seisman added maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog needs review This PR has higher priority and needs review. labels Mar 23, 2024
@seisman seisman added this to the 0.12.0 milestone Mar 23, 2024
@seisman
Add a function sequence_to_ctypes_array to convert a sequence to a ct…
7fe7ede
…ypes array
@seisman
seisman force-pushed the sequence_to_ctypes_array branch from b0d3c3d to 7fe7ede Compare March 23, 2024 08:08
@seisman seisman removed the needs review This PR has higher priority and needs review. label Mar 23, 2024
@seisman
seisman marked this pull request as draft March 23, 2024 08:16
@seisman seisman mentioned this pull request Mar 23, 2024
Add strings_to_ctypes_array to convert a sequence of strings into a ctypes array #3137
Merged
@seisman
Add notes about the strings_to_ctypes_array
57fc7fa
@seisman
seisman marked this pull request as ready for review March 23, 2024 08:52
@seisman seisman added needs review This PR has higher priority and needs review. run/benchmark Trigger the benchmark workflow in PRs and removed skip-changelog Skip adding Pull Request to changelog run/benchmark Trigger the benchmark workflow in PRs labels Mar 23, 2024
michaelgrund
michaelgrund approved these changes Mar 23, 2024
View reviewed changes
yvonnefroehlich
yvonnefroehlich reviewed Mar 23, 2024
View reviewed changes
Comment thread pygmt/clib/conversion.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

seisman and others added 2 commits March 24, 2024 02:42
@seisman @yvonnefroehlich
Update pygmt/clib/conversion.py
a28a8a6
Co-authored-by: Yvonne Fröhlich <[email protected]>
@seisman
Merge branch 'main' into sequence_to_ctypes_array
8d7d8d6
@seisman seisman changed the title Add a function sequence_to_ctypes_array to convert a sequence to a ctypes array Add sequence_to_ctypes_array to convert a sequence to a ctypes array Mar 23, 2024
seisman added 2 commits March 25, 2024 20:47
@seisman
Merge branch 'main' into sequence_to_ctypes_array
5984027
@seisman
Fix formatting
d4169f8
@seisman seisman added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Mar 25, 2024
@seisman
seisman merged commit 754a52f into main Mar 26, 2024
@seisman
seisman deleted the sequence_to_ctypes_array branch March 26, 2024 01:25
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@yvonnefroehlich yvonnefroehlich yvonnefroehlich left review comments
@michaelgrund michaelgrund michaelgrund approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

maintenance Boring but important stuff for the core devs

Projects

None yet

Milestone

0.12.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@seisman @michaelgrund @yvonnefroehlich
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.