Skip to content
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

Limitations of the kwargs_to_strings decorator not handling positional arguments #2361

Closed
seisman opened this issue Feb 12, 2023 · 4 comments · Fixed by #2826
Closed

Limitations of the kwargs_to_strings decorator not handling positional arguments #2361

seisman opened this issue Feb 12, 2023 · 4 comments · Fixed by #2826
Labels
bug Something isn't working
Milestone

Comments

@seisman
Copy link
Member

seisman commented Feb 12, 2023

Here are some limitations of the kwargs_to_strings decorator:

  1. Doesn't work for the default values of parameters:

#2208 (comment)

Please note that we can't use decorator @kwargs_to_strings(offset="sequence") here, because the decorator can only deal with keyword arguments and doesn't work for the default values. I.e., it doesn't work for Figure.timestamp() but works for Figure.timestamp(offset=["-54p", "-54p"]), although offset defaults to ["-54p", "-54p"].

@kwargs_to_strings(offset="sequence")
def timestamp(
    self,
    text=None,
    label=None,
    justification="BL",
    offset=("-54p", "-54p"),
    font="Helvetica",
    timefmt="%Y %b %d %H:%M:%S",
):
  1. Doesn't work if the parameter name is not given
>>> from pygmt import which
>>> # doesn't work
>>> which(["@hotspots.txt", "@earth_relief_01d_g"])
gmtwhich [ERROR]: File ['@hotspots.txt', not found!
gmtwhich [ERROR]: File '@earth_relief_01d_g'] not found!
>>> # works
>>> which(fname=["@hotspots.txt", "@earth_relief_01d_g"])
@seisman seisman added the bug Something isn't working label Feb 12, 2023
@weiji14 weiji14 changed the title Limitations of the kwargs_to_strings decorator Limitations of the kwargs_to_strings decorator not handling positional arguments Oct 15, 2023
@weiji14
Copy link
Member

weiji14 commented Oct 15, 2023

This issue would also apply to fig.text's textfiles parameter that uses sequence_space added in #325.

pygmt/pygmt/src/text.py

Lines 41 to 50 in c9d6147

textfiles="sequence_space",
angle="sequence_comma",
font="sequence_comma",
justify="sequence_comma",
c="sequence_comma",
p="sequence",
)
def text_(
self,
textfiles=None,

Should we remove sequence_space entirely since it is only used in pygmt.which and fig.text? And use the if is_nonstr_iter(fname): fname = " ".join(fname) patch in #2726?

@seisman
Copy link
Member Author

seisman commented Oct 15, 2023

And use the if is_nonstr_iter(fname): fname = " ".join(fname) patch in #2726?

No, it won't work for Figure.text, because textfiles can be a 2-D array, e.g., textfiles=[[1, 2, "A"], [3, 4, "B"]].

@weiji14
Copy link
Member

weiji14 commented Oct 15, 2023

And use the if is_nonstr_iter(fname): fname = " ".join(fname) patch in #2726?

No, it won't work for Figure.text, because textfiles can be a 2-D array, e.g., textfiles=[[1, 2, "A"], [3, 4, "B"]].

Ah ok, you're right. Let's keep sequence_space then. So #2726 will fix this issue entirely? Can we change Addresses #2726 to Fixes #2726 or was there something else?

@seisman
Copy link
Member Author

seisman commented Oct 15, 2023

So #2726 will fix this issue entirely?

No, see the first point:

Doesn't work for the default values of parameters:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants