Skip to content

which(), image() and legend() don't support pathlib.Path inputs #1832

Closed
@seisman

Description

@seisman

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions