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 — clib.Session.virtualfile_from_vectors: Now takes a sequence of vectors as its single argument (Passing multiple arguments will be unsupported in v0.16.0) by seisman · Pull Request #3522 · GenericMappingTools/pygmt

Conversation

@seisman

@seisman seisman commented Oct 16, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

In the Session.virtualfile_in method, we must prepare for _data that will be passed to different virtualfile_from_* methods. Currently, _data must be an iterable (e.g., _data = (data, ) even for the simplest case) and when pass it to _virtualfile_from, we need to unpack it like:

_virtualfile_from(*data)

The complexity is because, while most _virtualfile_from_* methods only take a single argument, the _virtualfile_from_vectors takes multiple arguments. The _virtualfile_from_vectors is defined like _virtualfile_from_vectors(*vectors) and must be called like _virtualfile_from_vectors(x, y, z).

This PR changes its definition to _virtualfile_from_vectors(vectors), and now it should be called like _virtualfile_from_vectors((x, y, z)).

With this breaking change, the virtualfile_in function can be simplified slightly, which I think is more readable. Then the question is, is it worth a breaking change?

Edit: Actually it's possible to introduce the new syntax without breaking backward compatibility. This is done in f5b0e8e.

Sorry, something went wrong.

Uh oh!

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

All reactions
@seisman seisman added maintenance Boring but important stuff for the core devs needs review This PR has higher priority and needs review. labels Oct 16, 2024
seisman added 2 commits October 16, 2024 20:40
@seisman
**Breaking**: clib.Session.virtualfile_from_vectors now takes only on…
29bd3f8
…e argument
@seisman
Backward compatible with the old way
f5b0e8e
@seisman
seisman force-pushed the refactor/virtualfile_from_vectors branch from a73a4bc to f5b0e8e Compare October 16, 2024 13:32
@seisman seisman changed the title POC: **Breaking**: clib.Session.virtualfile_from_vectors now takes only one argument **Deprecation**: clib.Session.virtualfile_from_vectors now takes only one argument Oct 16, 2024
@seisman seisman added this to the 0.14.0 milestone Oct 16, 2024
weiji14
weiji14 reviewed Oct 16, 2024
View reviewed changes
Comment thread pygmt/clib/session.py Resolved

Uh oh!

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

Comment thread pygmt/clib/session.py Resolved

Uh oh!

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

Comment thread pygmt/clib/session.py
Comment on lines +1805 to -1786
# "_data" is the data that will be passed to the _virtualfile_from function.
# "_data" defaults to "data" but should be adjusted for some cases.
_data = data
match kind:
case "arg" | "file" | "geojson" | "grid" | "image" | "stringio":

@weiji14 weiji14 Oct 16, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just put _data = data in the case _ below? I'd actually prefer if we make it more explicit like:

case "arg" | "file" | "geojson" | "grid" | "stringio":
    _data = data

So that if there's a new kind in the future, we know to add it explicitly.

Sorry, something went wrong.

Uh oh!

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

All reactions

@seisman seisman Oct 17, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually prefer if we make it more explicit like:

case "arg" | "file" | "geojson" | "grid" | "stringio":
    _data = data

So that if there's a new kind in the future, we know to add it explicitly.

We can't do it like this, because we're currently writing case statements like case "image" if data.dtype != "uint8":, which only catches the case when kind="image" and data.dtype != "uint8".

We can refactor the codes to:

case "arg" | "file" | "geojson" | "grid" | "stringio":
    _data = data
case "image":
    _data = data
    if data.dtype != "uint8":
        # do something
case "matrix":
    _data = data
    if data.dtype.kind not in "iuf":
    # do something

or

case "arg" | "file" | "geojson" | "grid" | "stringio":
    _data = data
case "image" if data.dtype != "uint8":
    raise ...
case "matrix" if data.dtype.kind not in "iuf":
    ...
case _:
    _data = data # this is necessary to catch cases like kind="matrix" and dtype in "iuf"  

I still prefer the current codes, which set _data to data by default and the match-case statements only need to deal with exceptions.

So that if there's a new kind in the future, we know to add it explicitly.

If there is a new kind in the future, _data=data is still the default. If needs special handling and we forget to add it, then the related tests will fail anyway.

Sorry, something went wrong.

Uh oh!

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

All reactions

@weiji14 weiji14 Oct 17, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, that makes sense, let's keep _data = data at the top then.

Sorry, something went wrong.

Uh oh!

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

All reactions
seisman added 6 commits October 17, 2024 07:11
@seisman
Merge branch 'main' into refactor/virtualfile_from_vectors
361d837
@seisman
Add type hints and format docstrings
f786b8e
@seisman
Further improve the docstrings
3893211
@seisman
Separate message strings
b7b87c6
@seisman
Reformat error message and remove the case '_' statement
6481df2
@seisman
Fix a typo
089ef3f
@seisman
seisman marked this pull request as ready for review October 17, 2024 06:53
@seisman seisman changed the title **Deprecation**: clib.Session.virtualfile_from_vectors now takes only one argument **Deprecation**: clib.Session.virtualfile_from_vectors now takes a sequence of vectors Oct 17, 2024
seisman
seisman commented Oct 17, 2024
View reviewed changes
Comment thread pygmt/clib/session.py Resolved

Uh oh!

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

Comment thread pygmt/clib/session.py Resolved

Uh oh!

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

seisman added 4 commits October 17, 2024 16:21
@seisman
Fix typos
1a43e38
@seisman
Merge branch 'main' into refactor/virtualfile_from_vectors
697d66b
@seisman
Merge branch 'main' into refactor/virtualfile_from_vectors
7ef4e01
@seisman
Merge branch 'main' into refactor/virtualfile_from_vectors
b2032c8
weiji14
weiji14 approved these changes Oct 21, 2024
View reviewed changes

@weiji14 weiji14 left a comment •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting very close to (finally) implementing #1076!

I've changed the label from 'maintenance' to 'deprecation'. Should we mention this is scheduled for removal in PyGMT v0.16.0?

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread pygmt/clib/session.py Resolved

Uh oh!

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

@weiji14 weiji14 added deprecation Deprecating a feature and removed maintenance Boring but important stuff for the core devs labels Oct 21, 2024
@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 Oct 21, 2024
@seisman seisman changed the title **Deprecation**: clib.Session.virtualfile_from_vectors now takes a sequence of vectors clib.Session.virtualfile_from_vectors: Now takes a sequence of vectors as its single argument (Passing multiple arguments will be unsupported in v0.16.0) Oct 21, 2024
seisman added 2 commits October 22, 2024 10:24
@seisman
Merge branch 'main' into refactor/virtualfile_from_vectors
c41806e
@seisman
Fix [skip ci]
61f323c
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Oct 22, 2024
@seisman
seisman merged commit 7eb93f2 into main Oct 22, 2024
@seisman
seisman deleted the refactor/virtualfile_from_vectors branch October 22, 2024 02:31
@seisman seisman mentioned this pull request Apr 3, 2025
Session.virtualfile_from_vectors: Remove the deprecated '*args' parameter [deprecated since v0.14.0] #3893
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@weiji14 weiji14 weiji14 approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

deprecation Deprecating a feature

Projects

None yet

Milestone

0.14.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

2 participants

@seisman @weiji14
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.