Skip to content

Typos in render_shapes/render_points parameter names are silently swallowed #627

Description

@timtreis

Typos in render_shapes/render_points parameter names are silently swallowed

Environment: spatialdata-plot 0.3.4.dev (main, commit 5cfedc7), Python 3.13


Problem

render_shapes and render_points accept **kwargs to support datashader_reduction (a documented but kwargs-only parameter). As a side effect, all unknown keyword arguments are silently discarded with no warning or error.

sdata.pl.render_shapes("s", fill_alph=0.5)           # typo for fill_alpha — silently ignored
sdata.pl.render_shapes("s", unknownparam=True)        # unknown — silently ignored
sdata.pl.render_shapes("s", datashader_reductioon="mean")  # typo in documented kwarg — silently ignored

This makes typos in parameter names invisible: the user gets the default behaviour, not the behaviour they requested, with no feedback.


Minimal reproducible example

import matplotlib; matplotlib.use("Agg")
import matplotlib.pyplot as plt
import geopandas as gpd
from shapely.geometry import box
import spatialdata as sd
from spatialdata.models import ShapesModel
import spatialdata_plot

shapes = ShapesModel.parse(gpd.GeoDataFrame(
    {"geometry": [box(0, 0, 1, 1)], "radius": [0.5]}, geometry="geometry"
))
sdata = sd.SpatialData(shapes={"s": shapes})

fig, ax = plt.subplots()
# All of these silently succeed — no TypeError, no warning
sdata.pl.render_shapes("s", typo_param=True).pl.show(ax=ax)
sdata.pl.render_shapes("s", fill_alph=0.5).pl.show(ax=ax)           # intended: fill_alpha
sdata.pl.render_shapes("s", datashader_reductioon="max").pl.show(ax=ax)  # typo in documented kwarg

Expected behaviour

TypeError: render_shapes() got unexpected keyword argument 'fill_alph'.
Did you mean 'fill_alpha'?

Actual behaviour

All three calls succeed silently. The user's typo is discarded and they get the default behaviour instead of the one they requested.


Fix sketch

After extracting the known kwargs (datashader_reduction, transfunc, vmin, vmax), validate that no unexpected keys remain:

known_kwargs = {"datashader_reduction", "transfunc", "vmin", "vmax"}
unexpected = set(kwargs) - known_kwargs
if unexpected:
    raise TypeError(
        f"render_shapes() got unexpected keyword argument(s): {sorted(unexpected)}"
    )

Alternatively, declare these parameters explicitly in the function signature so Python itself enforces the contract and IDEs provide autocomplete.


Triage tier: Tier 3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions