Skip to content

Commit 9c42f50

Browse files
authored
[BREAKING] Figure.text: Raise GMTTypeError if text is a sequence when position is given (#4065)
1 parent c0803a6 commit 9c42f50

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

pygmt/src/text.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,16 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
200200
data_is_required = position is None
201201
kind = data_kind(textfiles, required=data_is_required)
202202

203-
if position is not None and (text is None or is_nonstr_iter(text)):
204-
msg = "'text' can't be None or array when 'position' is given."
205-
raise GMTInvalidInput(msg)
203+
if position is not None:
204+
if text is None:
205+
msg = "'text' can't be None when 'position' is given."
206+
raise GMTInvalidInput(msg)
207+
if is_nonstr_iter(text):
208+
raise GMTTypeError(
209+
type(text),
210+
reason="Parameter 'text' can't be a sequence when 'position' is given.",
211+
)
212+
206213
if textfiles is not None and text is not None:
207214
msg = "'text' can't be specified when 'textfiles' is given."
208215
raise GMTInvalidInput(msg)

pygmt/tests/test_text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88
import pytest
99
from pygmt import Figure, config
10-
from pygmt.exceptions import GMTCLibError, GMTInvalidInput
10+
from pygmt.exceptions import GMTCLibError, GMTInvalidInput, GMTTypeError
1111
from pygmt.helpers import GMTTempFile
1212
from pygmt.helpers.testing import skip_if_no
1313

@@ -154,7 +154,7 @@ def test_text_invalid_inputs(region):
154154
fig.text(region=region, projection="x1c", textfiles="file.txt", text="text")
155155
with pytest.raises(GMTInvalidInput):
156156
fig.text(region=region, projection="x1c", position="MC", text=None)
157-
with pytest.raises(GMTInvalidInput):
157+
with pytest.raises(GMTTypeError):
158158
fig.text(
159159
region=region, projection="x1c", position="MC", text=["text1", "text2"]
160160
)

0 commit comments

Comments
 (0)