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
|
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?
I'm trying to fix a
pathlibbug of plot and plot3d in #1831 and find thatwhich(),image()andlegendalso don't supportpathlib.Pathinputs.To reproduce the issue, run:
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
pygmt/pygmt/src/histogram.py
Lines 150 to 152 in 8fe2d33
To fix the bug, the simplest solution is changing input file to a string type, for example, changing
fnametostr(fname). Do anyone have better and more general solutions?