Skip to content

BREAKING: Raise GMTTypeError exception for invalid types. Previously raise GMTInvalidInput - #3999

Merged
seisman merged 12 commits into
mainfrom
exception/typeerror
Jul 21, 2025
Merged

BREAKING: Raise GMTTypeError exception for invalid types. Previously raise GMTInvalidInput#3999
seisman merged 12 commits into
mainfrom
exception/typeerror

Conversation

@seisman

@seismanseisman commented Jul 15, 2025

Copy link
Copy Markdown
Member

Following PR #3985. Addressing #3707 and #3984.

This PR adds a new exception GMTTypeError. The error message is like:

Unrecognized data type: xxxx. Explain the reason.

@seismanseisman added this to the 0.17.0 milestone Jul 15, 2025
@seismanseisman added the enhancement Improving an existing feature label Jul 15, 2025
@seisman
seisman requested a review from CopilotJuly 15, 2025 06:02
@seismanseisman added the needs review This PR has higher priority and needs review. label Jul 15, 2025
@seisman
seisman marked this pull request as ready for review July 15, 2025 06:02

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the handling of invalid-type inputs by introducing and raising a new exception class GMTTypeError instead of GMTInvalidInput. Tests across many modules have been updated to expect GMTTypeError, and source files for core commands have been modified to import and raise the new exception. Additionally, the GMTTypeError class has been added to pygmt/exceptions.py.

Reviewed Changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 6 comments.

Show a summary per file
FileDescription
pygmt/exceptions.pyAdded GMTTypeError subclass of TypeError for invalid input types
pygmt/src/x2sys_cross.pySwitched invalid-type error from GMTInvalidInput to GMTTypeError
pygmt/src/text.pyUpdated array‐argument checks to raise GMTTypeError
pygmt/src/plot3d.pyChanged invalid‐array errors to raise GMTTypeError
pygmt/src/plot.pyChanged invalid‐array errors to raise GMTTypeError
pygmt/src/legend.pyChanged invalid‐type checks to raise GMTTypeError
pygmt/src/grdcut.pySwitched unsupported‐type error to GMTTypeError
pygmt/clib/session.pyReplaced several GMTInvalidInput raises with GMTTypeError, and updated docstrings
pygmt/tests/*Updated tests to import and expect GMTTypeError instead of GMTInvalidInput

Comment threadpygmt/tests/test_plot3d.py
Comment threadpygmt/tests/test_plot.py
Comment threadpygmt/tests/test_grdtrack.py
Comment threadpygmt/tests/test_grdimage.py
Comment threadpygmt/tests/test_grd2cpt.py Outdated
Comment threadpygmt/tests/test_clib_put_vector.py Outdated
@seismanseisman added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Jul 21, 2025
@seisman

Copy link
Copy Markdown
MemberAuthor

Ping @GenericMappingTools/pygmt-maintainers for final reivews. I plan to merge in 48 hours.

@yvonnefroehlichyvonnefroehlich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am fine with the changes, just a few minor suggestions and comments.

Comment threaddoc/api/index.rst
Comment threadpygmt/clib/session.py Outdated
Comment threadpygmt/src/text.py Outdated
raise GMTInvalidInput(msg)
raise GMTTypeError(
type(arg),
reason=f"Parameter {name!r} expects a scalar value or True.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With "scalar value", we refer to a float, or?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I've changed it back to "single".

Comment threadpygmt/src/text.py Outdated
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
@seismanseisman removed the final review call This PR requires final review and approval from a second reviewer label Jul 21, 2025
@seisman

Copy link
Copy Markdown
MemberAuthor

/format

@seisman
seisman merged commit eddc912 into mainJul 21, 2025
@seisman
seisman deleted the exception/typeerror branch July 21, 2025 11:52
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancementImproving an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@seisman@michaelgrund@weiji14@yvonnefroehlich