Skip to content

Commit

Permalink
Figure.ternary: Fix the crash for pd.DataFrame input with GMT 6.3-6.4 (
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Dec 26, 2022
1 parent 2f65595 commit e512e10
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pygmt/src/ternary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
ternary - Plot data on ternary diagrams.
"""
import pandas as pd
from packaging.version import Version
from pygmt.clib import Session
from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias

Expand Down Expand Up @@ -79,6 +81,12 @@ def ternary(self, data, alabel=None, blabel=None, clabel=None, **kwargs):
kwargs["L"] = "/".join([alabel, blabel, clabel])

with Session() as lib:
# Patch for GMT < 6.5.0.
# See https://github.com/GenericMappingTools/pygmt/pull/2138
if Version(lib.info["version"]) < Version("6.5.0") and isinstance(
data, pd.DataFrame
):
data = data.to_numpy()
file_context = lib.virtualfile_from_data(check_kind="vector", data=data)
with file_context as infile:
lib.call_module(
Expand Down

0 comments on commit e512e10

Please sign in to comment.