Skip to content

Commit 32063b4

Browse files
authored
Fix pathlib support for plot and plot3d (#1831)
1 parent 6ee851b commit 32063b4

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

pygmt/src/plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def plot(self, data=None, x=None, y=None, size=None, direction=None, **kwargs):
226226
and data.geom_type.isin(["Point", "MultiPoint"]).all()
227227
): # checking if the geometry of a geoDataFrame is Point or MultiPoint
228228
kwargs["S"] = "s0.2c"
229-
elif kwargs.get("S") is None and kind == "file" and data.endswith(".gmt"):
229+
elif kwargs.get("S") is None and kind == "file" and str(data).endswith(".gmt"):
230230
# checking that the data is a file path to set default style
231231
try:
232232
with open(which(data), mode="r", encoding="utf8") as file:

pygmt/src/plot3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def plot3d(
196196
and data.geom_type.isin(["Point", "MultiPoint"]).all()
197197
): # checking if the geometry of a geoDataFrame is Point or MultiPoint
198198
kwargs["S"] = "u0.2c"
199-
elif kwargs.get("S") is None and kind == "file" and data.endswith(".gmt"):
199+
elif kwargs.get("S") is None and kind == "file" and str(data).endswith(".gmt"):
200200
# checking that the data is a file path to set default style
201201
try:
202202
with open(which(data), mode="r", encoding="utf8") as file:

pygmt/tests/test_plot.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
import datetime
66
import os
7+
from pathlib import Path
78

89
import numpy as np
910
import pandas as pd
@@ -452,8 +453,11 @@ def test_plot_datetime():
452453
return fig
453454

454455

455-
@pytest.mark.mpl_image_compare
456-
def test_plot_ogrgmt_file_multipoint_default_style():
456+
@pytest.mark.mpl_image_compare(
457+
filename="test_plot_ogrgmt_file_multipoint_default_style.png"
458+
)
459+
@pytest.mark.parametrize("func", [str, Path])
460+
def test_plot_ogrgmt_file_multipoint_default_style(func):
457461
"""
458462
Make sure that OGR/GMT files with MultiPoint geometry are plotted as
459463
squares and not as line (default GMT style).
@@ -467,7 +471,9 @@ def test_plot_ogrgmt_file_multipoint_default_style():
467471
with open(tmpfile.name, "w", encoding="utf8") as file:
468472
file.write(gmt_file)
469473
fig = Figure()
470-
fig.plot(data=tmpfile.name, region=[0, 2, 1, 3], projection="X2c", frame=True)
474+
fig.plot(
475+
data=func(tmpfile.name), region=[0, 2, 1, 3], projection="X2c", frame=True
476+
)
471477
return fig
472478

473479

pygmt/tests/test_plot3d.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Tests plot3d.
33
"""
44
import os
5+
from pathlib import Path
56

67
import numpy as np
78
import pytest
@@ -423,8 +424,11 @@ def test_plot3d_scalar_xyz():
423424
return fig
424425

425426

426-
@pytest.mark.mpl_image_compare
427-
def test_plot3d_ogrgmt_file_multipoint_default_style():
427+
@pytest.mark.mpl_image_compare(
428+
filename="test_plot3d_ogrgmt_file_multipoint_default_style.png"
429+
)
430+
@pytest.mark.parametrize("func", [str, Path])
431+
def test_plot3d_ogrgmt_file_multipoint_default_style(func):
428432
"""
429433
Make sure that OGR/GMT files with MultiPoint geometry are plotted as cubes
430434
and not as line (default GMT style).
@@ -440,7 +444,7 @@ def test_plot3d_ogrgmt_file_multipoint_default_style():
440444
file.write(gmt_file)
441445
fig = Figure()
442446
fig.plot3d(
443-
data=tmpfile.name,
447+
data=func(tmpfile.name),
444448
perspective=[315, 25],
445449
region=[0, 2, 0, 2, 0, 2],
446450
projection="X2c",

0 commit comments

Comments
 (0)