Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 10 additions & 3 deletions pygmt/src/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,16 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
data_is_required = position is None
kind = data_kind(textfiles, required=data_is_required)

if position is not None and (text is None or is_nonstr_iter(text)):
msg = "'text' can't be None or array when 'position' is given."
raise GMTInvalidInput(msg)
if position is not None:
if text is None:
msg = "'text' can't be None when 'position' is given."
raise GMTInvalidInput(msg)
if is_nonstr_iter(text):
raise GMTTypeError(
type(text),
reason="Parameter 'text' can't be a sequence when 'position' is given.",
)

if textfiles is not None and text is not None:
msg = "'text' can't be specified when 'textfiles' is given."
raise GMTInvalidInput(msg)
Expand Down
4 changes: 2 additions & 2 deletions pygmt/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
import pytest
from pygmt import Figure, config
from pygmt.exceptions import GMTCLibError, GMTInvalidInput
from pygmt.exceptions import GMTCLibError, GMTInvalidInput, GMTTypeError
from pygmt.helpers import GMTTempFile
from pygmt.helpers.testing import skip_if_no

Expand Down Expand Up @@ -154,7 +154,7 @@ def test_text_invalid_inputs(region):
fig.text(region=region, projection="x1c", textfiles="file.txt", text="text")
with pytest.raises(GMTInvalidInput):
fig.text(region=region, projection="x1c", position="MC", text=None)
with pytest.raises(GMTInvalidInput):
with pytest.raises(GMTTypeError):
fig.text(
region=region, projection="x1c", position="MC", text=["text1", "text2"]
)
Expand Down
Loading