Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make color validation more forgiving #29122

Merged
merged 4 commits into from
Nov 10, 2019

Conversation

AllenDowney
Copy link
Contributor

The current version throws a false positive if the style string contains s or o, which are valid marker styles and not colors. For example:

style='s', color='C3'

should be legal, but currently throws an error.

My suggestion is to check for only the letters that are color codes.

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

@WillAyd
Copy link
Member

WillAyd commented Oct 21, 2019

Can you add a test for this? I'm not super familiar with this code but the intent of the ValueError getting raises also doesn't seem to match what you are asking for here, so test would help clarify that

@WillAyd WillAyd added the Visualization plotting label Oct 21, 2019
@AllenDowney
Copy link
Contributor Author

I know that in theory it is best for the person submitting a PR to write tests, but I have almost no familiarity with the code base, so it would take me much longer than someone who knows the code, and I am more likely to break something.

@AllenDowney
Copy link
Contributor Author

But I can clarify the test case. This example:

style='s', color='C3'

Should be legal because the style is specifying a shape, not a color.

Instead it raises "Cannot pass 'style' string with a color symbol and 'color' keyword argument.

The line of code I'm changing checks whether the style string contains any letters a-z, seemingly on the assumption that all letters in a style string are color codes. But there are several letters, including s and o, that indicate shapes, not colors.

@WillAyd
Copy link
Member

WillAyd commented Oct 21, 2019

You can look at the tests defined in pandas/tests/plotting. Both test_series.py and test_frame.py should have examples you can copy; the color validation tests may be the best

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above if you could add tests would be great

@TomAugspurger
Copy link
Contributor

Whoops, I've done something horribly wrong to your branch @AllenDowney. Will fix it up.

@TomAugspurger
Copy link
Contributor

Ahh, I see. This was against 0.25.x. All our PRs go through master first.

@TomAugspurger TomAugspurger changed the base branch from 0.25.x to master November 5, 2019 18:20
@TomAugspurger TomAugspurger added this to the 1.0 milestone Nov 5, 2019
@AllenDowney
Copy link
Contributor Author

AllenDowney commented Nov 5, 2019 via email

@TomAugspurger TomAugspurger merged commit 0f15046 into pandas-dev:master Nov 10, 2019
@TomAugspurger
Copy link
Contributor

Thanks Allen!

keechongtan added a commit to keechongtan/pandas that referenced this pull request Nov 11, 2019
…ndexing-1row-df

* upstream/master: (109 commits)
  stronger typing in libreduction (pandas-dev#29502)
  API: rename labels to codes (pandas-dev#29509)
  CLN: remove unnecessary type checks (pandas-dev#29517)
  implement _BaseGrouper (pandas-dev#29520)
  CLN: F-string formatting in pandas/_libs/*.pyx (pandas-dev#29527)
  Fixed more SS03 errors (pandas-dev#29540)
  consolidate dim checks (pandas-dev#29536)
  REF: separate out _get_cython_func_and_vals (pandas-dev#29537)
  remove unnecessary exception (pandas-dev#29538)
  TST:Add test to check single category col returns series with single row slice (pandas-dev#29521)
  Make color validation more forgiving (pandas-dev#29122)
  DOC: update bottleneck repo and documentation urls (pandas-dev#29516)
  TST: add test for df construction from dict with tuples (pandas-dev#29497)
  add test for pd.melt dtypes preservation (pandas-dev#29510)
  updated DataFrame.equals docstring (pandas-dev#29496)
  Resolved merge conflicts (pandas-dev#29506)
  DOC: Improved pandas/compact/__init__.py (pandas-dev#29507)
  DOC: Update performance comparison section of io docs (pandas-dev#28890)
  TST: add test for df.where() with category dtype (pandas-dev#29454)
  DOC: Fix docs on merging categoricals. (pandas-dev#28185)
  ...
Reksbril pushed a commit to Reksbril/pandas that referenced this pull request Nov 18, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
@joooeey
Copy link
Contributor

joooeey commented Apr 27, 2020

The following test is wrong!

def test_style_single_ok(self):
    s = pd.Series([1, 2])
    ax = s.plot(style="s", color="C3")
    assert ax.lines[0].get_color() == ["C3"]

The color of a single Line2D cannot usually be a list. Perhaps a list of the 3 RGB or the 4 RGBa values. But not ["C3"]. I'll change this test in PR #33821 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants