Skip to content

Conversation

@seisman
Copy link
Member

@seisman seisman commented Dec 8, 2025

This PR adds suffix support to the Alias class, which is necessary to support some options, e.g., wiggle's -G option has a syntax -Gfill[+n][+p]. Currently, we have to write a custom function to parse the argument. With the suffix support, it can be greatly simplified.

@seisman seisman added enhancement Improving an existing feature needs review This PR has higher priority and needs review. labels Dec 9, 2025
@seisman seisman added this to the 0.18.0 milestone Dec 9, 2025
pygmt/alias.py Outdated
# - If any Alias has a suffix, return a list of values, for repeated GMT options
# like -Cblue+l -Cred+r
# - Otherwise, concatenate into a single string for combined modifiers like
# -BWSen+ttitle+gblue.
Copy link
Member Author

Choose a reason for hiding this comment

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

        G=[
            Alias(fillpositive, name="fillpositive", suffix="+p"),
            Alias(fillnegative, name="fillnegative", suffix="+n"),
        ],

Taking wiggle's -G option as an example. In the previous version, the values will be concatenated into a single string, so fillpositive="blue", fillnegative="red" will be -Gblue+pred+n, which is invalid.

I've updated the logic of AliasSystem, so that it will return a list of values, rather than concatenating them, when any Alias has a suffix.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe this a short note about this should be added to the docstring. I'm afraid that this will be missed, e.g. in #4234 (comment) if we forget that suffix has this special treatment.

Copy link
Member Author

Choose a reason for hiding this comment

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

What about moving the whole note lines 303-310 to docstrings?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, that works too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 7ceea09

@seisman seisman marked this pull request as ready for review December 9, 2025 02:51
@seisman seisman marked this pull request as draft December 11, 2025 01:55
@seisman seisman removed the needs review This PR has higher priority and needs review. label Dec 11, 2025
@seisman seisman modified the milestones: 0.18.0, 0.19.0 Dec 25, 2025
@seisman seisman marked this pull request as ready for review January 18, 2026 13:34
@seisman seisman added needs review This PR has higher priority and needs review. and removed needs review This PR has higher priority and needs review. labels Jan 18, 2026
Comment on lines +148 to +150
# True is converted to an empty string with the optional prefix and suffix.
if value is True:
return f"{prefix}"
return f"{prefix}{suffix}"
Copy link
Member

Choose a reason for hiding this comment

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

Would it be confusing if we allowed both prefix and suffix when value is True? E.g. at #4234 (comment), we used prefix, but it could also be suffix.

Or I guess it doesn't matter, and we should just be consistent that every if-branch in this _to_string function handles prefix and suffix.

Copy link
Member Author

Choose a reason for hiding this comment

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

Would it be confusing if we allowed both prefix and suffix when value is True? E.g. at #4234 (comment), we used prefix, but it could also be suffix.

prefix and suffix cannot coexist. This function does do the check to avoid too much function overhead. It's our responsibility to pass the correct prefix/suffix values.

Comment on lines +162 to +163
Alias(positive_fill, name="positive_fill", suffix="+p"),
Alias(negative_fill, name="negative_fill", suffix="+n"),
Copy link
Member

Choose a reason for hiding this comment

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

Maybe take this opportunity to update the type-hint of postive_fill and negative_fill at L47-48 above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 12e451c

@seisman seisman added the needs review This PR has higher priority and needs review. label Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improving an existing feature needs review This PR has higher priority and needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants