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
4 changes: 2 additions & 2 deletions pygmt/params/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _validate(self):
)

# shade_offset must be a sequence of two values or None.
if self.shade_offset and not (
if self.shade_offset is not None and not (
is_nonstr_iter(self.shade_offset) and len(self.shade_offset) == 2
):
raise GMTValueError(
Expand All @@ -91,7 +91,7 @@ def _shade(self) -> list[str | float] | None:
"""
Shading for the box, formatted as a list of 1-3 values, or None.
"""
_shade_offset = self.shade_offset or []
_shade_offset = [] if self.shade_offset is None else self.shade_offset
return [v for v in (*_shade_offset, self.shade_fill) if v is not None] or None

@property
Expand Down
5 changes: 4 additions & 1 deletion pygmt/params/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ def _validate(self):
reason="Expect a sequence of two values.",
)
case "inside" | "outside":
if self.refpoint not in _valid_anchors:
if (
not isinstance(self.refpoint, str)
or self.refpoint not in _valid_anchors
):
raise GMTValueError(
self.refpoint,
description="reference point",
Expand Down
11 changes: 11 additions & 0 deletions pygmt/tests/test_params_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test the Box class.
"""

import numpy as np
import pytest
from pygmt.exceptions import GMTParameterError, GMTValueError
from pygmt.params import Box
Expand Down Expand Up @@ -57,3 +58,13 @@ def test_params_box_invalid_innerborder():
"""
with pytest.raises(GMTParameterError):
_ = str(Box(inner_gap="2p"))


def test_params_box_shade_offset_array_like():
"""
Test that shade_offset accepts numpy arrays and rejects empty sequences.
"""
assert str(Box(shade_offset=np.array([1, 2]))) == "+s1/2"
assert str(Box(shade_offset=np.array([1, 2]), shade_fill="red")) == "+s1/2/red"
with pytest.raises(GMTValueError):
Box(shade_offset=[])
9 changes: 9 additions & 0 deletions pygmt/tests/test_params_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,12 @@ def test_params_position_invalid_anchor():
"""
with pytest.raises(GMTValueError):
Position((10, 20), cstype="mapcoords", anchor="XX")


def test_params_position_unhashable_justification_code():
"""
Test that an unhashable refpoint raises GMTValueError rather than TypeError.
"""
for cstype in ("inside", "outside"):
with pytest.raises(GMTValueError):
Position(["T", "L"], cstype=cstype)