Skip to content

Commit

Permalink
Fix pathlib support for plot and plot3d (#1831)
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman authored Apr 5, 2022
1 parent 6ee851b commit 32063b4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pygmt/src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def plot(self, data=None, x=None, y=None, size=None, direction=None, **kwargs):
and data.geom_type.isin(["Point", "MultiPoint"]).all()
): # checking if the geometry of a geoDataFrame is Point or MultiPoint
kwargs["S"] = "s0.2c"
elif kwargs.get("S") is None and kind == "file" and data.endswith(".gmt"):
elif kwargs.get("S") is None and kind == "file" and str(data).endswith(".gmt"):
# checking that the data is a file path to set default style
try:
with open(which(data), mode="r", encoding="utf8") as file:
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def plot3d(
and data.geom_type.isin(["Point", "MultiPoint"]).all()
): # checking if the geometry of a geoDataFrame is Point or MultiPoint
kwargs["S"] = "u0.2c"
elif kwargs.get("S") is None and kind == "file" and data.endswith(".gmt"):
elif kwargs.get("S") is None and kind == "file" and str(data).endswith(".gmt"):
# checking that the data is a file path to set default style
try:
with open(which(data), mode="r", encoding="utf8") as file:
Expand Down
12 changes: 9 additions & 3 deletions pygmt/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
import datetime
import os
from pathlib import Path

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -452,8 +453,11 @@ def test_plot_datetime():
return fig


@pytest.mark.mpl_image_compare
def test_plot_ogrgmt_file_multipoint_default_style():
@pytest.mark.mpl_image_compare(
filename="test_plot_ogrgmt_file_multipoint_default_style.png"
)
@pytest.mark.parametrize("func", [str, Path])
def test_plot_ogrgmt_file_multipoint_default_style(func):
"""
Make sure that OGR/GMT files with MultiPoint geometry are plotted as
squares and not as line (default GMT style).
Expand All @@ -467,7 +471,9 @@ def test_plot_ogrgmt_file_multipoint_default_style():
with open(tmpfile.name, "w", encoding="utf8") as file:
file.write(gmt_file)
fig = Figure()
fig.plot(data=tmpfile.name, region=[0, 2, 1, 3], projection="X2c", frame=True)
fig.plot(
data=func(tmpfile.name), region=[0, 2, 1, 3], projection="X2c", frame=True
)
return fig


Expand Down
10 changes: 7 additions & 3 deletions pygmt/tests/test_plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Tests plot3d.
"""
import os
from pathlib import Path

import numpy as np
import pytest
Expand Down Expand Up @@ -423,8 +424,11 @@ def test_plot3d_scalar_xyz():
return fig


@pytest.mark.mpl_image_compare
def test_plot3d_ogrgmt_file_multipoint_default_style():
@pytest.mark.mpl_image_compare(
filename="test_plot3d_ogrgmt_file_multipoint_default_style.png"
)
@pytest.mark.parametrize("func", [str, Path])
def test_plot3d_ogrgmt_file_multipoint_default_style(func):
"""
Make sure that OGR/GMT files with MultiPoint geometry are plotted as cubes
and not as line (default GMT style).
Expand All @@ -440,7 +444,7 @@ def test_plot3d_ogrgmt_file_multipoint_default_style():
file.write(gmt_file)
fig = Figure()
fig.plot3d(
data=tmpfile.name,
data=func(tmpfile.name),
perspective=[315, 25],
region=[0, 2, 0, 2, 0, 2],
projection="X2c",
Expand Down

0 comments on commit 32063b4

Please sign in to comment.