Skip to content

Conversation

@willschlitzer
Copy link
Contributor

@willschlitzer willschlitzer commented Jan 10, 2026

Description of proposed changes

This adds input validation for quantile_value, specifically that it is a number, and that it is between 0 and 100. It also adds testing for this input validations, including modifying test_binstats_quantile() to pass a numeric value as a string.

This commit adds input validation for quantile value, specifically that it is a number, and that it is between 0 and 100.
It also adds testing for these changes, including modifying test_binstats_quantile() to pass a numeric value as a string.
Comment on lines +170 to +178
quantile_error_message = "quantile_value must be a value between 0 and 100."
try:
quantile_value_float = float(quantile_value)
except (ValueError, TypeError):
raise GMTInvalidInput(quantile_error_message) from None
if 0 <= quantile_value_float <= 100:
aliasdict["C"] += f"{quantile_value_float}"
else:
raise GMTInvalidInput(quantile_error_message) from None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should support a string value like quantile_value="75".

Comment on lines +170 to +178
quantile_error_message = "quantile_value must be a value between 0 and 100."
try:
quantile_value_float = float(quantile_value)
except (ValueError, TypeError):
raise GMTInvalidInput(quantile_error_message) from None
if 0 <= quantile_value_float <= 100:
aliasdict["C"] += f"{quantile_value_float}"
else:
raise GMTInvalidInput(quantile_error_message) from None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
quantile_error_message = "quantile_value must be a value between 0 and 100."
try:
quantile_value_float = float(quantile_value)
except (ValueError, TypeError):
raise GMTInvalidInput(quantile_error_message) from None
if 0 <= quantile_value_float <= 100:
aliasdict["C"] += f"{quantile_value_float}"
else:
raise GMTInvalidInput(quantile_error_message) from None
if not (isinstance(quantile_value, (int, float)) and (0 <= quantile_value <= 100):
msg = "quantile_value must be a value between 0 and 100."
raise GMTInvalidInput(msg)
aliasdict["C"] += f"{quantile_value}"

@seisman seisman changed the title Add input validation for quantile_value in binstats.py. pygmt.binstats: Validate the quantile_value parameter Jan 11, 2026
@seisman seisman added maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog labels Jan 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants