Skip to content

Refactor layer creation#1041

Merged
has2k1 merged 9 commits intomainfrom
refactor-layer-creation
Mar 9, 2026
Merged

Refactor layer creation#1041
has2k1 merged 9 commits intomainfrom
refactor-layer-creation

Conversation

@has2k1
Copy link
Owner

@has2k1 has2k1 commented Mar 9, 2026

API Changes

Removed geom.to_layer(), stat.to_layer(), annotate.to_layer(), layer.from_geom() and layer.from_stat(). Use layer(geom=...) and layer(stat=...) directly.

The constructor now handles both geom-first and stat-first creation. When only a stat is provided, the geom is automatically derived from the stat's default.

# Before
layer.from_geom(geom_point())
layer.from_stat(stat_bin())
geom_point().to_layer()

# After
layer(geom=geom_point())
layer(stat=stat_bin())
layer(geom=geom_point())

has2k1 added 9 commits March 6, 2026 17:42
This allows us to extend stats with less boilerplate code. i.e.
DEFAULT_PARAMS becomes optional.
Signal that these are raw, unpartitioned kwargs consumed once by the
layer during construction. This is a preparatory rename for the layer
creation refactor.
…_geom

- Move stat and position instantiation from geom.__init__ to
  layer.from_geom, making geom construction side-effect-free
- Replace module-level _verify_layer_arguments with layer._verify_arguments
  staticmethod, removing the redundant kwargs parameter
- Delete dead geom._verify_arguments method
- Update tests to call .to_layer() where stat/position access is needed
- Add layer.from_stat staticmethod that creates a geom from the stat
  then delegates to layer.from_geom
- Simplify stat.to_layer to just call layer.from_stat(self)
- Change layer.setup_data to set geom.params["stat_params"] instead of
  flat-merging stat.params into geom.params, preventing namespace
  collisions and keeping geom params clean
- Update geom_dotplot to access stat params via params["stat_params"]
Accept strings, classes, or instances for geom/stat/position in
layer.__init__. Add _resolve_geom, _resolve_stat, _resolve_position
module-level helpers. Simplify from_geom/from_stat to thin delegates.
…yer resolvers

These factory methods are now inlined into the layer.py resolver
functions (_resolve_stat, _resolve_position, layer.from_stat),
centralising all component resolution in one place. Tests updated
to exercise resolution through the layer API.
… and layer(stat=...)

Extract _lookup_stat for pure spec→class/instance resolution and add
stat-first detection in layer.__init__ so that layer(stat="bin") derives
the correct geom. This makes from_geom, from_stat, and to_layer
redundant — all callers now use layer() directly.
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 83.65385% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.79%. Comparing base (bbf7fe3) to head (fcd4ea3).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
plotnine/layer.py 82.55% 6 Missing and 9 partials ⚠️
plotnine/geoms/geom_dotplot.py 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1041      +/-   ##
==========================================
- Coverage   86.83%   86.79%   -0.04%     
==========================================
  Files         203      203              
  Lines       13806    13812       +6     
  Branches     1702     1706       +4     
==========================================
  Hits        11988    11988              
- Misses       1273     1275       +2     
- Partials      545      549       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@has2k1 has2k1 merged commit fcd4ea3 into main Mar 9, 2026
13 of 14 checks passed
@has2k1 has2k1 deleted the refactor-layer-creation branch March 9, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant