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

Add 'color' and 'size' to arguments #44856

Merged
merged 24 commits into from Apr 7, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 30 additions & 2 deletions pandas/plotting/_core.py
Expand Up @@ -1127,6 +1127,13 @@ def bar(self, x=None, y=None, **kwargs):
axis of the plot shows the specific categories being compared, and the
other axis represents a measured value.
"""
c = kwargs.pop('c', None)
color = kwargs.pop('color', None)
if c is not None and color is not None:
raise TypeError("Specify exactly one of `c` and `color`")
if c is not None or color is not None:
kwargs.setdefault('c', color or c)

return self(kind="bar", x=x, y=y, **kwargs)

@Appender(
Expand Down Expand Up @@ -1213,6 +1220,13 @@ def barh(self, x=None, y=None, **kwargs):
axis of the plot shows the specific categories being compared, and the
other axis represents a measured value.
"""
c = kwargs.pop('c', None)
color = kwargs.pop('color', None)
if c is not None and color is not None:
raise TypeError("Specify exactly one of `c` and `color`")
if c is not None or color is not None:
kwargs.setdefault('c', color or c)

return self(kind="barh", x=x, y=y, **kwargs)

def box(self, by=None, **kwargs):
Expand Down Expand Up @@ -1582,7 +1596,7 @@ def pie(self, **kwargs):
raise ValueError("pie requires either y column or 'subplots=True'")
return self(kind="pie", **kwargs)

def scatter(self, x, y, s=None, c=None, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

you can deprecate but not rename as that is a breaking change

these are matpotlib names but not objecting to the change per se

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see your point but I need some help to solve it. What is best practice in this situation and how does a deprication warning work?

Copy link
Member

Choose a reason for hiding this comment

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

@mosc9575 check some other PRs which deprecate arguments for examples https://github.com/pandas-dev/pandas/pulls?q=is%3Apr+depr+is%3Amerged+

Copy link
Contributor Author

@mosc9575 mosc9575 Dec 12, 2021

Choose a reason for hiding this comment

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

@jreback I used the wrong word. I did not "rename", I added size and color to avoid braking code.

Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't keep both in the signature, that'd be confusing

I'd suggest:

  • use color and size in the signature
  • if color is None, take c from kwargs (likewise for size and s)
  • raise an error if someone passes both color and c
  • check that the docs consistently use color and size

Copy link
Contributor Author

@mosc9575 mosc9575 Dec 12, 2021

Choose a reason for hiding this comment

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

@MarcoGorelli Thank you. I go with your suggestions. I will edit my PR.

Copy link
Member

Choose a reason for hiding this comment

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

thanks - will also need tests to cover the new behaviour

def scatter(self, x, y, **kwargs):
attack68 marked this conversation as resolved.
Show resolved Hide resolved
"""
Create a scatter plot with varying marker point size and color.

Expand Down Expand Up @@ -1665,7 +1679,21 @@ def scatter(self, x, y, s=None, c=None, **kwargs):
... c='species',
... colormap='viridis')
"""
return self(kind="scatter", x=x, y=y, s=s, c=c, **kwargs)
s = kwargs.pop('s', None)
size = kwargs.pop('size', None)
if s is not None and size is not None:
raise TypeError("Specify exactly one of `s` and `size`")
MarcoGorelli marked this conversation as resolved.
Show resolved Hide resolved
if s is not None or size is not None:
kwargs.setdefault('s', s or size)

c = kwargs.pop('c', None)
color = kwargs.pop('color', None)
if c is not None and color is not None:
raise TypeError("Specify exactly one of `c` and `color`")
if c is not None or color is not None:
kwargs.setdefault('c', c or color)

return self(kind="scatter", x=x, y=y, **kwargs)

def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None, **kwargs):
"""
Expand Down