has2k1 / has2k1/plotnine

Too many line types results in unclear exception.

Open
#351 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement
Dominant language
Python
Stars
4.8k
Forks
254
Avg merge
10h 35m
Merged PRs (30d)
9

Description

(this is on current git head 52e33218b86165d90f5313d57c22465223219e98 )

import pandas as pd
import plotnine as p9
import numpy as np
line_type_count = 5
df = pd.DataFrame(
    {
        "x": np.random.random(size=100),
        "y": np.random.random(size=100),
        "lt": (["a_" + str(x) for x in range(line_type_count)] * 200)[:100],
    }
)
import plotnine as p9

g = p9.ggplot(df)
g += p9.geom_line(p9.aes(x="x", y="y", group="lt", linetype="lt"))
g

is answered with a couple of warnings:

/ssd/upstream/dev/lib/python3.7/site-packages/mizani/palettes.py:683: UserWarning: Palette can return a maximum of 4 values. 5 were requested from it.
  warnings.warn(msg.format(max_n, n))
/ssd/upstream/plotnine_dev/linestyle_errors/plotnine/geoms/geom_path.py:75: PlotnineWarning: geom_path: Removed 20 rows containing missing values.
  warn(msg.format(n1-n2), PlotnineWarning)
/ssd/upstream/dev/lib/python3.7/site-packages/mizani/palettes.py:683: UserWarning: Palette can return a maximum of 4 values. 5 were requested from it.
  warnings.warn(msg.format(max_n, n))

which could be improved by actually naming the Palette in question,
and and exception

ValueError: Unrecognized linestyle: nan

somewhere in guides (it's a long traceback).

This is not particularly helpful.

For comparison, scale_color_brewer(type='qual') degrades gracefully (warnings, grey for additional levels), scale_color_manual dies with a similarly unhelpful message: "ValueError: Invalid RGBA argument: nan", not in guides though.

Can we fix this globally, or do we have to approach each scale by itself?

Also we should unify the approaches, either filter the values (and warn),
raise an appropriate exception (possibly with a much shorter stack-trace?) or degrade the plot and warn (as scale_color_brewer(type='qual') seems to do it).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied example with five line types on the referenced commit. Inspect mizani/palettes.py and plotnine/geoms/geom_path.py, then trace the guides and scale handling that produces nan. Compare the brewer and manual scale behavior; done means excess levels receive a consistent, informative warning, exception, or degradation path.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, pandas, python
Domain
data-visualization
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.