Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CLN: clean color selection in _matplotlib/style #37203
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
CLN: clean color selection in _matplotlib/style #37203
Changes from 23 commits
0f1b99a
901453a
201b25f
8e13df5
37a820d
3883a13
f93743c
b4c3267
6af1543
31125f7
45647a4
393ae46
fe66213
1626108
79b0f08
f513bdb
76f7663
0f0f4bc
b8daf79
37734e8
765836f
4479e37
dd9efd7
f0ea701
dedd0dd
b369834
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 add a doc-string.
also the current summary is not very descriptive, nor is the function name .
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 changed it into
_derive_colors
. I am not sure if you would consider it a better alternative. I thought of having a more verbose name (like_derive_colors_from_cmap_color_and_type
, but that does not seem reasonable to me, although I added the explanation in the docstring.Anyway derive seems a better verb, implying some logic underneath.
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 cast seems unnecessary - is there an error this solves?
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, cast is necessary.
At this point
color
is of typeUnion[Color, Collection[Color]]
. And for some reason_is_floats_color
check does not filter outCollection[Color]
. So, instead of ignoring, I added cast here.mypy error if removing cast.
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.
Functions can't narrow types yet in mypy, but regardless this is pretty confusing. Can you try to refactor this to make things clearer?
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 do not know how to make it even clearer.
The logic is the following.
a. a single string color
b. or multiple string color (like 'rgbk')
c. or single float color (0.1, 0.2, 0.3)
d. or multiple float colors
Is the logic confusing or the two cast statements are?
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.
@WillAyd, I updated the logic a little bit.
Casting is still there as there are no other options to make mypy happy.
Please let me know what you think about this implementation.
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 could just use pytest.importorskip see pandas\tests\plotting\test_converter.py or other test modules testing optional dependencies. e.g. pytables
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.
Did that. Please check if this is what you suggested.
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 you could combine this one with the test above, and add
cycler_color
to parameterize since those two tests look almost identical and test basically the same except how colors are definedThere 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 it's nicer to just test the case where num_color </>/= color, so 3 parametrizations is enough. no need to change here though ^^