Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pathlib support for plot and plot3d #1831

Merged
merged 3 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 "S" not in kwargs and kind == "file" and data.endswith(".gmt"):
elif "S" not in kwargs 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 "S" not in kwargs and kind == "file" and data.endswith(".gmt"):
elif "S" not in kwargs 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