Skip to content

fix(geom_path): allow layers without data - #1136

Merged
has2k1 merged 3 commits into
has2k1:mainfrom
raashish1601:fix/empty-path-layers
Oct 8, 2026
Merged

has2k1 merged 3 commits into
has2k1:mainfrom
raashish1601:fix/empty-path-layers

Conversation

@raashish1601

Copy link
Copy Markdown
Contributor

Plotting an empty data frame with a path based layer raises a KeyError:

data = pd.DataFrame({"x": pd.Series([], dtype=float)})
ggplot(data, aes("x")) + stat_ecdf()
# KeyError: "['y'] not in index"

The same happens with geom_freqpoly and geom_qq_line. When a stat gets no rows it returns no computed columns, so the layer data has no y. geom_path.handle_na then selects ["x", "y", "size", "color", "linetype"] strictly. Other geoms (e.g. geom_histogram, geom_density) already draw nothing in this case, and ggplot2's GeomPath$handle_na only looks at the columns that are present (data[names(data) %in% c(...)]).

This makes handle_na use only the columns that exist.

Testing: added test_empty_layer_data, which fails on main and passes with the fix. tests/test_geom_path_line_step.py, tests/test_stat_ecdf.py, tests/test_geom_freqpoly.py and tests/test_geom_qq_qq_line.py pass, ruff is clean. Added a changelog entry under Bug Fixes.

Comment thread tests/test_geom_path_line_step.py Outdated
@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.87%. Comparing base (ac9cfce) to head (630b619).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1136      +/-   ##
==========================================
- Coverage   88.87%   88.87%   -0.01%     
==========================================
  Files         229      229              
  Lines       17292    17291       -1     
  Branches     2203     2203              
==========================================
- Hits        15368    15367       -1     
  Misses       1295     1295              
  Partials      629      629              

☔ View full report in Codecov by Harness.
📢 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 8e02b38 into has2k1:main Oct 8, 2026
8 of 9 checks passed
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.

2 participants