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

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

merged 24 commits into from
Apr 7, 2022

Conversation

mosc9575
Copy link
Contributor

This changes use more intuitive names for 'color' and 'size' and use the same notation like in '_bar_or_line_doc'.

This changes use more intuitive names for 'color' and 'size' and use the same notation like in '_bar_or_line_doc'.
@@ -1582,7 +1582,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

@mosc9575 mosc9575 changed the title Rename 'c' to 'color' and 's' to 'size' Add 'color' and 'size' to arguments Dec 12, 2021
@@ -1582,7 +1582,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):
def scatter(self, x, y, size=None, s=None, color=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.

this can be used as positional arguments and your change is not backwards compatible, best to use the order:

self, x, y, s, c, size, color, **kwargs

Copy link
Contributor

Choose a reason for hiding this comment

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

actually I misread the purpose of this PR, shouldn't we be replicating matplotlibs arguments? Can you indicate why you want to make this change?

Copy link
Member

Choose a reason for hiding this comment

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

this can be used as positional arguments

ah yes, thanks - @mosc9575 please ignore part of my previous comment

let's keep s and c in the signature then, add color and size after them, and deprecate s and c?

Copy link
Member

Choose a reason for hiding this comment

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

Can you indicate why you want to make this change?

Just for consistency really, as in bar and barh it's color

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.

Can you indicate why you want to make this change?

I opend this issue, because c was not intuitive for me. I don't have the matplotlib background, I normally work with bokeh, and they have the same functionality of c named color. Then I was searching the pandas documentation and found color used for hbar and bar. Therefor I thought this is not consitent and a misstake by this function. To be honest, I first understood the naming when I looked into matplotlib today. But it is still not "intuitive" to me.

Please let me know if you think this shouldn't be changed at all.

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.

I was reading the matplotlib documentation for a while and the same problem can be found there. I will wait for a response to my issue #21795 and change both in one step, if this is approved.

Copy link
Contributor

Choose a reason for hiding this comment

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

i think we could also accept color size and and not deprecate

Copy link
Member

@MarcoGorelli MarcoGorelli Dec 12, 2021

Choose a reason for hiding this comment

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

Yes, agreed, I'd go with:

  • keep signature as is
  • if c is None, take color from kwargs (likewise for s and size)
  • raise an error if someone passes both color and c, or size and s (and test this)

Conversely, for bar:

  • keep signature as is
  • if color is None, take c from kwargs
  • raise an error if someone passes both color and c (and test this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Matplolib won't change and I think the sugessted changes by @MarcoGorelli are good. I try to edit my PR soon.

@jreback jreback added API - Consistency Internal Consistency of API/Behavior Visualization plotting labels Dec 14, 2021
@jreback
Copy link
Contributor

jreback commented Jan 16, 2022

@mosc9575 if you'd merge master and addrress comments

@pep8speaks
Copy link

pep8speaks commented Jan 17, 2022

Hello @mosc9575! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2022-04-06 15:00:47 UTC

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Left a comment on error messages (also, will need tests)

pandas/plotting/_core.py Show resolved Hide resolved
@MarcoGorelli MarcoGorelli self-requested a review January 19, 2022 16:57
pandas/plotting/_core.py Outdated Show resolved Hide resolved
pandas/plotting/_core.py Outdated Show resolved Hide resolved
pandas/plotting/_core.py Outdated Show resolved Hide resolved
pandas/plotting/_core.py Outdated Show resolved Hide resolved
pandas/plotting/_core.py Outdated Show resolved Hide resolved
pandas/plotting/_core.py Outdated Show resolved Hide resolved
pandas/plotting/_core.py Outdated Show resolved Hide resolved
Copy link
Contributor

@attack68 attack68 left a comment

Choose a reason for hiding this comment

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

This is now looking pretty good to me. one or two comments just to remove code duplication in the tests, but it's looking quite minimal now.
After it goes green Im happy to approve.

Oh, and this should also be added to the doc strings and there should be a release note in the whatsnew if you havent added it already.

@@ -0,0 +1,47 @@
.. _whatsnew_141:
Copy link
Member

Choose a reason for hiding this comment

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

Can you revert changes to this file please?


.. _whatsnew_150.enhancements.styler:

Styler
Copy link
Member

Choose a reason for hiding this comment

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

Lot's of unrelated changes are showing up in this file

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

needs a whatsnew note for 1.5.0

size : str, int or array-like, optional
The color of each point. Alias for `s`.
`s` and `size` aren't allowed at the same time.
.. versionadded:: 1.4.1
Copy link
Member

Choose a reason for hiding this comment

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

1.5.0

@MarcoGorelli MarcoGorelli self-requested a review March 7, 2022 12:18
@@ -1603,7 +1603,8 @@ def scatter(self, x, y, s=None, c=None, **kwargs):
The column name or column position to be used as vertical
coordinates for each point.
s : str, scalar or array-like, optional
The size of each point. Possible values are:
The size of each point. ``size`` is also accepted as an alternate keyword
Copy link
Contributor

Choose a reason for hiding this comment

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

i think we can list s, size : str.... here (i don't know if we do this for aliases elsewhere but should follow the same pattern), e.g. see read_csv where we have some aliases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I follow the syntax of read_csv I have to write

size : str, scalar or array-like, optional
    Alias for s

I did not find a notation like s, size: str.

@mosc9575 mosc9575 requested a review from jreback March 8, 2022 11:55
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

@jreback jreback added this to the 1.5 milestone Apr 7, 2022
@jreback
Copy link
Contributor

jreback commented Apr 7, 2022

should we deprecate passing c/s ? (or are these also accepted by mpl)?

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Apr 7, 2022

are these also accepted by mpl?

looks like they're inconsistent, scatter takes c, bar takes color

https://matplotlib.org/3.5.0/api/_as_gen/matplotlib.pyplot.scatter.html
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.bar.html

@jreback
Copy link
Contributor

jreback commented Apr 7, 2022

are these also accepted by mpl?

looks like they're inconsistent, scatter takes c, bar takes color

https://matplotlib.org/3.5.0/api/_as_gen/matplotlib.pyplot.scatter.html https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.bar.html

ok over time prob a good idea to use color/size (even if mpl accepts more).

@jreback jreback merged commit 8a4abfa into pandas-dev:main Apr 7, 2022
@jreback
Copy link
Contributor

jreback commented Apr 7, 2022

thanks @mosc9575

@mosc9575
Copy link
Contributor Author

mosc9575 commented Apr 7, 2022

You are welcome. I appreciated your cooperation and help.

@mosc9575 mosc9575 deleted the patch-1 branch April 7, 2022 17:28
yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this pull request Jul 13, 2022
phofl added a commit to phofl/pandas that referenced this pull request Nov 16, 2022
This reverts commit 8a4abfa.

# Conflicts:
#	doc/source/whatsnew/v1.5.0.rst
#	pandas/plotting/_core.py
#	pandas/tests/plotting/frame/test_frame_color.py
MarcoGorelli pushed a commit that referenced this pull request Nov 17, 2022
* Revert "Add 'color' and 'size' to arguments (#44856)"

This reverts commit 8a4abfa.

# Conflicts:
#	doc/source/whatsnew/v1.5.0.rst
#	pandas/plotting/_core.py
#	pandas/tests/plotting/frame/test_frame_color.py

* Add whatsnew
MarcoGorelli pushed a commit to MarcoGorelli/pandas that referenced this pull request Nov 17, 2022
MarcoGorelli added a commit that referenced this pull request Nov 17, 2022
MarcoGorelli pushed a commit to MarcoGorelli/pandas that referenced this pull request Nov 18, 2022
…as-dev#49734)

* Revert "Add 'color' and 'size' to arguments (pandas-dev#44856)"

This reverts commit 8a4abfa.

# Conflicts:
#	doc/source/whatsnew/v1.5.0.rst
#	pandas/plotting/_core.py
#	pandas/tests/plotting/frame/test_frame_color.py

* Add whatsnew
mliu08 pushed a commit to mliu08/pandas that referenced this pull request Nov 27, 2022
…as-dev#49734)

* Revert "Add 'color' and 'size' to arguments (pandas-dev#44856)"

This reverts commit 8a4abfa.

# Conflicts:
#	doc/source/whatsnew/v1.5.0.rst
#	pandas/plotting/_core.py
#	pandas/tests/plotting/frame/test_frame_color.py

* Add whatsnew
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Stale Visualization plotting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Pandas plot does not accept Columns for color keyword
5 participants