-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
Conversation
This changes use more intuitive names for 'color' and 'size' and use the same notation like in '_bar_or_line_doc'.
pandas/plotting/_core.py
Outdated
@@ -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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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+
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
andsize
in the signature - if
color
isNone
, takec
fromkwargs
(likewise forsize
ands
) - raise an error if someone passes both
color
andc
- check that the docs consistently use
color
andsize
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
pandas/plotting/_core.py
Outdated
@@ -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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
isNone
, takecolor
fromkwargs
(likewise fors
andsize
) - raise an error if someone passes both
color
andc
, orsize
ands
(and test this)
Conversely, for bar
:
- keep signature as is
- if
color
isNone
, takec
fromkwargs
- raise an error if someone passes both
color
andc
(and test this)
There was a problem hiding this comment.
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.
@mosc9575 if you'd merge master and addrress comments |
There was a problem hiding this 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)
There was a problem hiding this 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.
doc/source/whatsnew/v1.4.1.rst
Outdated
@@ -0,0 +1,47 @@ | |||
.. _whatsnew_141: |
There was a problem hiding this comment.
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?
doc/source/whatsnew/v1.5.0.rst
Outdated
|
||
.. _whatsnew_150.enhancements.styler: | ||
|
||
Styler |
There was a problem hiding this comment.
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
There was a problem hiding this 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
pandas/plotting/_core.py
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.5.0
pandas/plotting/_core.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we deprecate passing c/s ? (or are these also accepted by mpl)? |
looks like they're inconsistent, https://matplotlib.org/3.5.0/api/_as_gen/matplotlib.pyplot.scatter.html |
ok over time prob a good idea to use color/size (even if mpl accepts more). |
thanks @mosc9575 |
You are welcome. I appreciated your cooperation and help. |
This reverts commit 8a4abfa. # Conflicts: # doc/source/whatsnew/v1.5.0.rst # pandas/plotting/_core.py # pandas/tests/plotting/frame/test_frame_color.py
Co-authored-by: Patrick Hoefler <[email protected]>
…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
…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
This changes use more intuitive names for 'color' and 'size' and use the same notation like in '_bar_or_line_doc'.