Closed
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
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?