Skip to content

DataFrame.plot error when both 'color' and 'style' arguments are passed (GH9671) #9674

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

Closed

Conversation

davidbrochart
Copy link

closes #9671

self.style can be a list of strings or a string. If it is a string, we make a list containing that string, so that we only have to deal with a list of strings. We check every element in that list and raise an error if it has a color symbol.
The test makes sure that calling plot() and passing both color and style arguments is allowed if there is no color symbol in the style string(s), and that passing both color and style arguments is not allowed if there is a color symbol in the style string(s). This test is done for a dataframe and for a series.

@TomAugspurger
Copy link
Contributor

Thanks. In the future, you don't need to open up a new PR. You can push changes to your original pull request and github will pick them up. I made a couple comments inline. Please let me know if you've got any questions or if anything I wrote doesn't make sense.

The tests look great! I'm glad you included one that should raise an exception (I always forget these). I just had a few things to make them fit into our test framework.

Once you make those changes you can test these specific ones with nosetests test_graphics:TestDataFramePlots.<test_name>. You also might want to make new tests instead of attaching them to test_plot. That way if they fail in the future we can easily see which test failed.

@@ -991,6 +991,18 @@ def test_plot(self):
df = DataFrame({'x': [1, 2], 'y': [3, 4]})
with tm.assertRaises(TypeError):
df.plot(kind='line', blarg=True)
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of wrapping the code in try / except plots, just call the function.

ax = df.plot(color=['red', 'black'], style=['-', '--']) and then make sure the color and styles match what's expected.
You can get the actual linestyle with result = [line.get_linestyle() for line in ax.lines]
Then compare that to the expected with self.assertEqual(result, ['-', '--'])

Same thing for the colors, [line.get_color() for line in ax.lines]

@davidbrochart
Copy link
Author

Thanks for your comments Tom. I made the changes you suggested.

@jreback jreback added the Visualization plotting label Mar 20, 2015
@jreback jreback added this to the 0.16.1 milestone Mar 20, 2015
@jreback jreback changed the title Fix for issue #9671 DataFrame.plot error when both 'color' and 'style' arguments are passed (GH9671) Mar 23, 2015
@TomAugspurger
Copy link
Contributor

@davidbrochart could you rebase on master and add a release note in doc/source/whatsnew/v0.16.1.txt? Thanks.

You can also squash your commits down to one. Let me know if you have any troubles.

David BROCHART and others added 3 commits April 6, 2015 08:57
…en both 'color' and 'style' keywords were passed and there was no color symbol in the style strings (this should be allowed)
@davidbrochart
Copy link
Author

@TomAugspurger I rebased on master and added a release note. Hope this is fine.

@TomAugspurger
Copy link
Contributor

Merged via f00d6bb

Thanks @davidbrochart

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.

DataFrame.plot error when both 'color' and 'style' arguments are passed
6 participants