File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 99from pygmt ._typing import PathLike , TableLike
1010from pygmt .alias import Alias , AliasSystem
1111from pygmt .clib import Session
12+ from pygmt .exceptions import GMTTypeError , GMTValueError
1213from pygmt .helpers import build_arg_list , fmt_docstring , use_alias
1314
1415
@@ -166,6 +167,16 @@ def binstats(
166167 )
167168 aliasdict .merge (kwargs )
168169 if statistic == "quantile" :
170+ if not isinstance (quantile_value , (int , float )):
171+ raise GMTTypeError (
172+ quantile_value , reason = "quantile_value must be an 'int' or 'float'."
173+ )
174+ if not (0 <= quantile_value <= 100 ):
175+ raise GMTValueError (
176+ quantile_value ,
177+ description = "quantile_value" ,
178+ reason = "Must be a value between 0 and 100." ,
179+ )
169180 aliasdict ["C" ] += f"{ quantile_value } "
170181
171182 with Session () as lib :
Original file line number Diff line number Diff line change 88import pytest
99from pygmt import binstats
1010from pygmt .enums import GridRegistration , GridType
11+ from pygmt .exceptions import GMTTypeError , GMTValueError
1112from pygmt .helpers import GMTTempFile
1213
1314
@@ -51,6 +52,24 @@ def test_binstats_no_outgrid():
5152 npt .assert_allclose (temp_grid .mean (), 4227489 )
5253
5354
55+ def test_binstats_invalid_quantile_value ():
56+ """
57+ Tests the input validation for quantile_value.
58+ """
59+ kwargs = {
60+ "data" : "@capitals.gmt" ,
61+ "spacing" : 5 ,
62+ "statistic" : "quantile" ,
63+ "search_radius" : "1000k" ,
64+ "aspatial" : "2=population" ,
65+ "region" : "g" ,
66+ }
67+ with pytest .raises (GMTValueError ):
68+ binstats (quantile_value = 175 , ** kwargs )
69+ with pytest .raises (GMTTypeError ):
70+ binstats (quantile_value = "invalid" , ** kwargs )
71+
72+
5473def test_binstats_quantile ():
5574 """
5675 Test binstats quantile statistic functionality.
You can’t perform that action at this time.
0 commit comments