Skip to content

Figure.choropleth: Validate the input data type and the column name - #4852

Open
seisman wants to merge 1 commit into
mainfrom
choropleth/validate
Open

Figure.choropleth: Validate the input data type and the column name#4852
seisman wants to merge 1 commit into
mainfrom
choropleth/validate

Conversation

@seisman

@seisman seisman commented Aug 23, 2026

Copy link
Copy Markdown
Member

As shown by the example below, passing an invalid column leads to a segmentation fault:

In [2]: import geopandas
   ...: import pygmt
   ...: world = geopandas.read_file(
   ...:     "https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip"
   ...: )
   ...: world["POP_EST"] *= 1e-6  # Population in millions
   ...: fig = pygmt.Figure()
   ...: fig.basemap(region=[-19.5, 53, -38, 37.5], projection="M15c", frame=True)
   ...: pygmt.makecpt(cmap="bilbao", series=(0, 270, 10), reverse=True)
   ...: fig.choropleth(world, column="invalid", pen="0.3p,gray10")
   ...: fig.colorbar(frame=True)
   ...: fig.show()
zsh: segmentation fault  ipython

This PR checks the input data type and also check if the specified column exists in the geo-like objects.

@seisman seisman added this to the 0.20.0 milestone Aug 23, 2026
@seisman seisman added enhancement Improving an existing feature needs review This PR has higher priority and needs review. labels Aug 23, 2026
@seisman
seisman requested a lite review from Copilot August 23, 2026 15:43

Copilot AI 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

Adds early validation to Figure.choropleth to prevent invalid inputs and column names from causing segmentation faults.

Changes:

  • Validates supported data types and column names.
  • Excludes geometry columns from attribute validation.
  • Adds regression tests for invalid inputs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Summary
pygmt/src/choropleth.py Adds input and column validation; attribute-less geo-like objects still require column validation handling.
pygmt/tests/test_choropleth.py Adds tests for invalid columns and data types.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pygmt/src/choropleth.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improving an existing feature needs review This PR has higher priority and needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants