Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 5 additions & 3 deletions pygmt/params/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Pattern(BaseParam):
The pattern to use. It can be specified in two forms:

- An integer in the range of 1-90, corresponding to one of 90 predefined 64x64
bit-patterns
bit-patterns. [Default is 1].
- Name of a 1-, 8-, or 24-bit image raster file, to create customized, repeating
images using image raster files.
dpi
Expand Down Expand Up @@ -69,7 +69,7 @@ class Pattern(BaseParam):
>>> fig.show()
"""

pattern: int | PathLike
pattern: int | PathLike = 1
dpi: int | None = None
bgcolor: str | None = None
fgcolor: str | None = None
Expand All @@ -80,7 +80,9 @@ def _validate(self):
Validate the parameters.
"""
# Integer pattern number must be in the range 1-90.
if isinstance(self.pattern, int) and not (1 <= self.pattern <= 90):
if not isinstance(self.pattern, (PathLike, int)) or (
isinstance(self.pattern, int) and not (1 <= self.pattern <= 90)
):
raise GMTValueError(
self.pattern,
description="pattern number",
Expand Down
4 changes: 3 additions & 1 deletion pygmt/tests/test_params_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ def test_pattern():

def test_pattern_invalid_pattern():
"""
Test that an invalid pattern number raises a GMTValueError.
Test that an invalid pattern value or number raises a GMTValueError.
"""
with pytest.raises(GMTValueError):
_ = Pattern(None) # Value that is neither int nor PathLike
with pytest.raises(GMTValueError):
_ = str(Pattern(0))
with pytest.raises(GMTValueError):
Expand Down
Loading