Skip to content

New Alias System: Add the private _to_string function #3986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 10, 2025

Conversation

seisman
Copy link
Member

@seisman seisman commented Jun 21, 2025

Part 1 of PR #3238

@seisman seisman added this to the 0.17.0 milestone Jun 23, 2025
@seisman seisman added the enhancement Improving an existing feature label Jun 23, 2025
@seisman seisman force-pushed the AliasSystem/to_string branch from 01b8267 to 8f5c52b Compare June 29, 2025 07:18
pygmt/alias.py Outdated
Comment on lines 112 to 123
match mapping:
case False:
pass
case True:
value = value[0]
case Mapping():
if value not in mapping and value not in mapping.values():
raise GMTValueError(
value,
description="value for parameter {name!r}" if name else "value",
choices=mapping.keys(),
)
Copy link
Member Author

Choose a reason for hiding this comment

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

mapping=True means using the first letter of a long-form argument as its short-form argument. For example, resolution="high" will be mapped to resolution="h". If we don't support mapping=True, lines 112-123 can be simplified to a few lines:

                if value not in mapping and value not in mapping.values():
                    raise GMTValueError(
                        value,
                        description="value for parameter {name!r}" if name else "value",
                        choices=mapping.keys(),
                    )

but without mapping=True, we need to write something like

mapping={"full": "f", "high": "h", "intermediate": "i", "low": "l", "crude": "c"}

when calling the _to_string function.

Copy link
Member

Choose a reason for hiding this comment

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

I think better to be explicit (use the full mapping {"key": "value"} dict), and just have one way to parse things. We can use the first letter for resolution, but for others like interpolation/-n, where the mapping is {"b-spline": "b", "bicubic": "c", "bilinear": "l", ...}, it doesn't work.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've removed mapping=True in commit c499aab.

Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

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

This looks ok to me, was there anything else you wanted to add?

@seisman
Copy link
Member Author

seisman commented Jul 7, 2025

This looks ok to me, was there anything else you wanted to add?

Need to wait for #3985

@seisman seisman added the needs review This PR has higher priority and needs review. label Jul 9, 2025
@seisman seisman marked this pull request as ready for review July 9, 2025 22:24
@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. final review call This PR requires final review and approval from a second reviewer labels Jul 10, 2025
@seisman seisman merged commit 7a682ff into main Jul 10, 2025
25 of 26 checks passed
@seisman seisman deleted the AliasSystem/to_string branch July 10, 2025 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants