-
Notifications
You must be signed in to change notification settings - Fork 235
Closed
Labels
bugSomething isn't workingSomething isn't working
Milestone
Description
I'm trying to fix a pathlib bug of plot and plot3d in #1831 and find that which(), image() and legend also don't support pathlib.Path inputs.
To reproduce the issue, run:
>>> import pygmt
>>> from pathlib import Path
>>> pygmt.which(Path("abc.txt"))
>>> fig = pygmt.Figure()
>>> fig.image(Path("abc.png"))
>>> fig.legend(spec=Path("legend.txt"))
The error message is: TypeError: sequence item 0: expected str instance, PosixPath found.
Other functions work because their input file is wrapped in a context manager, like
Lines 150 to 152 in 8fe2d33
| with file_context as infile: | |
| arg_str = " ".join([infile, build_arg_string(kwargs)]) | |
| lib.call_module("histogram", arg_str) |
To fix the bug, the simplest solution is changing input file to a string type, for example, changing fname to str(fname). Do anyone have better and more general solutions?
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working